在视图控制器中使用多个 tableview 时使用委托方法
在我的应用程序中,我想在一个 ViewController 中使用 3 个 tableview.问题是我如何单独使用 UITableViewDelegate 方法.例如;我可以通过标记为每个 UITableView 单独使用 cellForRowAtIndexPath 方法.但是,我不知道如何为每个 tableview 使用 numberOfRowsInSection 或 numberOfSectionsInTableView 方法.可能吗?
In my app I want to use 3 tableviews in a single ViewController. The problem is how can I use UITableViewDelegate methods seperately. For example; I can use cellForRowAtIndexPath method seperately for each UITableView by tagging. But, I have no idea about using numberOfRowsInSection or numberOfSectionsInTableView methods for each tableview differently. Is it possible?
在 YourViewController.h 中制作 3 个 UITableView 变量:
Make 3 UITableView variables in YourViewController.h:
YourViewController : UIViewController
{
UITableView* tableView1;
UITableView* tableView2;
UITableView* tableView3;
}
YourViewController.m:
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == tableView1)
{
//Your code
}
if (tableView == tableView2)
{
//Your code
}
if (tableView == tableView3)
{
//Your code
}
}