I am using two UITableView
s in a UIViewController
, how can I populate the row and cells in both tableviews? When I give for the second tableview it says the duplicate declaration of the number of rows in section etc.
That's why the dataSource/delegate methods have a tableView
parameter. Depending on its value, you can return different numbers/cells/...
- (void)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == _myTableViewOutlet1)
return 10;
else
return 20;
}
All of your UITableViewDelegate
and UITableViewDatasource
methods will be implemented only once. You just need to check for which table view the method is being called.
if (tableView == tblView1) {
//Implementation for first tableView
}
else {
//Implementation for second tableView
}
this will work in all of TableView's delegate and datasource methods as tableView
is common parameter in all of your methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {}
Look here and here
This Link also has the solution of your issue.
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With