我在视图控制器中有 2 个表视图(表 1,表 2)。我有 2 个数据数组(dataArray1,dataArray2)。我想用相应的数据数组加载表视图,即(table1 = dataArray1,table2 = dataArray2)。我正在尝试下面的代码。但是应用程序崩溃了?这段代码有什么问题?任何帮助,将不胜感激。请不要建议使用 2 个视图控制器。
- (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;
}