我有一个选项卡栏控制器,里面只有两个按钮。每个按钮都指向一个不同的表视图,但两个表视图都继承了我的TableViewController.m类。我在每个表视图中都有一个动态单元格。它们都有一个不同的名字(第一个是"地点列表",第二个是"照片和地点列表")。我想在每个选项卡(指向表视图)中显示不同的内容,但我不知道如何显示。我想我需要在控制器中识别我的动态单元格的名称才能实现这一点,但我也不知道如何实现。请帮忙!这是TableViewController.m 中的方法
- (UITableViewCell *)tableView:(UITableView *)sender
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Places List";
UITableViewCell *cell = [sender dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [cities objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [restOfPlaces objectAtIndex:indexPath.row];
return cell;
}
您可以选择
-
将ivar添加到
TableViewController
,并在实例化时将其设置为选项卡索引 -
询问选项卡BarController
[self.tabBarController.viewControllers indexOfObject:self];
这两者都是丑陋的解决方案,我可能会考虑重组。