0

我有一个标签栏控制器,里面只有两个按钮。每个都转到一个不同的表视图,但两个表视图都继承自我的 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;

}
4

1 回答 1

0

You can either

  1. add an ivar to the TableViewController and set it to the tab index when it is instantiated

  2. Ask the tabBarController

    [self.tabBarController.viewControllers indexOfObject:self];
    

Both of these are ugly solutions and I would probably think about restructuring.

于 2012-04-07T01:26:41.960 回答