I have 2 tableviews (table1,table2) in a view controller. I have 2 data arrays (dataArray1, dataArray2). I want to load the table views with corresponding data arrays i.e.(table1 = dataArray1, table2 = dataArray2).I am trying the below code. But app is crashed? What's wrong in this code? Any help would be appreciated. Please don't suggest to use 2 view controllers.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(tableView == self.table1)
return [dataArray1 count];
if(tableView == self.table2)
return [dataArray2 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
if(tableView == self.table1)
{
cell.textLabel.text =[dataArray1 objectAtIndex:indexPath.row];
}
if(tableView == self.table2)
{
cell.textLabel.text =[dataArray2 objectAtIndex:indexPath.row];
}
return cell;
}