Nora Alnashwan Nora Alnashwan - 26 days ago 9
iOS Question

n view controllers or n cells

I have a scenario where the user is transformed to a new view controller

vc2
when he presses
add
button.

depending on where he came from, required fields will change. For instance, if he choose to add a task he should enter
title
,
due date
and
time
, but when he choose to add a person he should enter
contact info
.

Is it better to have two separate view controllers (
vc2a
,
vc2b
) or one table view controller
vc2
that contains prototype of all cells for the two case, but every time I call
cellForRowAtIndexPath
, I have to check from where I come.

for me as a developer it is easier to have different view controller in storyboard especially when n>2, but if that can make a difference in performance things will change.

Thanks in advance.

Answer

As per my opinion it is better to do this task in a single view controller, provided you are performing similar next action after adding a task of adding a person.

And instead of putting up the checks in cellForRowAtIndexPath because it is called multiple times do place a check in numberOfRowsInSection.

In numberOfRowsInSection do

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

  OMGOrderDetailsSectionType sectionType = [[self.tableViewLayoutArray objectAtIndex:section] integerValue];

  if (sectionType == 0) {
    if(self.isContactsType) {
      return 1;
    }
  }
  else if (sectionType == 1) {
    if(self.isTaskType) {
      return 1;
    }
  }
  return 0;
}

Rest remains same for cellForRow, do configure both type of cells.

Comments