0

I have two UITableViews that I want to put into my app and obviously would need to set the properties of each of them (cellforRowAtIndexPath, numberOfRowsInSection).

How would I do this with two UITableViews?

Would I put an if statement (please explain) in these methods, or are there separate ways to do this?

  • You could set the `tag` property of each table view and check it in each of the delegate methods. – The Kraken May 08 '13 at 23:23
  • 1
    You have two UITableViews in the same view controller? – ari gold May 08 '13 at 23:24
  • FYI, that's a highly irregular practice. If you're working on an app for sale on the App Store, you might want to rethink your design in order to stay in accordance with the Apple HIG. – The Kraken May 08 '13 at 23:29
  • you can use 1 table with multiple sections, so you will have 2 (or more) visibly separate table part with multiple rows in both – nzs May 08 '13 at 23:46
  • Well my app is a mail client, so I need a table view on the side for folders and another one for the actual messages. –  May 09 '13 at 00:24

3 Answers3

1

Those are not "properties". They are methods; in particular, they are messages to the data source and delegate of the table view. Each table view gets to designate what object should be its delegate and data source. (Even those need not be the same object, but they usually are.)

So. If the tables are different, then why not have the data source and delegate of Table 1 be one object, and the data source and delegate of Table 2 be another object?

But if that is impossible, and both tables must have the same object as their data source and delegate, then yes, you will obviously need to distinguish one table from the other. That, after all, is what you typically do when you have a table and a search results table based on it.

matt
  • 515,959
  • 87
  • 875
  • 1,141
1

If you are creating by IBOutlet set tag for each UITableview in properties window then if you want to set datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   if(tableView.tag == 1)
     {
      return 1;
     }
    else
      {
       return 2;
      }
}

same way set for cellforRowAtIndexpath.hope will help

Sugan S
  • 1,782
  • 7
  • 25
  • 47
0

To display two tables simultaneously you may be beter off creating two view controllers rather than distinguishing tableviews in a single controller. Do you really want to take small iPhone screen space displaying both the folder list and actual mail content at once? UI where controllers are pushed/popped has lots of advantages. But if you want something different you may want to have a look at implementations of slide menu interface. That will show you how to implement two controllers visible simultaneously.

On iPad it is different and API provides a split view or master-detail interface.

Community
  • 1
  • 1
dmitri
  • 3,183
  • 23
  • 28