我有一个需要使用2个UITableViews
的ViewController。
1总是显示,而另一个将在您单击视图上的按钮后显示为弹出窗口。
通常我将委托和datasource
设置为文件所有者。然而,由于UITableViews
中的一个是弹出窗口,我不知道如何最好地解决这个问题。
例如,我如何处理这部分-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
请指教。
您应该在控制器中声明的两个表视图都有实例变量:
@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
UITableView *mainTableView;
UITableView *popupTableView;
}
在每个数据源或委托方法中,您可以检查调用者传递的表视图:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == mainTableView)
{
// Code to create and return a main table view cell
}
else if(tableView == popupTableView)
{
// Code to create and return a popup table view cell
}
}