2010-01-21 34 views
0

我只有1的tableView类,但4个细胞类。我将相同的tableView添加到应用程序中存在的所有viewController。区别在于单元格的类型(准确地说,类)。我想根据的viewController其中的tableView存在更改类细胞。另外,单元格的内容视图是在单元类的另一个子类中绘制的。请提供一个解决方案或方法来实现此功能。 提前致谢。变化类TableViewCell的,其中的tableView是本

+1

您的意思是说,不同控制器中的所有tableview都使用相同的委托和数据源类吗? – Vladimir 2010-01-21 10:29:53

+0

是所有viewControllers初始化相同TableViewController和使用[self.view addSubview:TableViewController.view]中的tableView增加。数据源是在TableViewController,但代表的是初始化的TableViewController的的viewController。 – Nishit 2010-01-21 11:09:11

回答

1

你也许应该使用每个视图控制器不同的表视图(如果你没有的话)。

通常,您还可以为每个表视图使用不同的数据源/委托(例如,您可以使用每个视图控制器)。但是,如果您必须对所有四个表视图使用相同的类作为数据源/委托,tableView:cellForRowAtIndexPath:(和其他委托方法)会为您提供表视图作为第一个参数,因此您可以返回正确的像这样的单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (tableView == myTableViewOne) { 
     // dequeue or allocate/init and configure/return the cell for the first table view here 
    } else if (tableView == myTableViewTwo) { 
     // dequeue or allocate/init and configure/return the cell for the second table view here 
    } else if (tableView == myTableViewThree) { 
     // dequeue or allocate/init and configure/return the cell for the third table view here 
    } else { 
     // dequeue or allocate/init and configure/return the cell for the fourth table view here 
    } 
} 
1

询问的tableView为它的使用NSObjects -class方法类的名称,并使用它在使用什么样细胞类决定。

相关问题