Nora Alnashwan Nora Alnashwan - 4 months ago 43
iOS Question

n view controllers or n cells

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

when he presses

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

Is it better to have two separate view controllers (
) or one table view controller
that contains prototype of all cells for the two case, but every time I call
, 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.


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.