开发者社区 问答 正文

在使用批量tableview时使用delegates

我的ViewController中有3个tableView,可不可以实现单独使用UITableViewDelegate方法?比如,可以分别对每个UITableView使用cellForRowAtIndexPath方法,但是不知道对每个tableView单独用numberOfRowsInSection或者numberOfSectionsInTableView有什么不同?可以实现吗?

展开
收起
爵霸 2016-03-24 12:06:30 1771 分享 版权
1 条回答
写回答
取消 提交回答
  • 可以啊
    :D

    设置3个UITableView变量,放在你的 ViewController.h 文件中:

    在你的 ViewController : UIViewController

    {
        UITableView* tableView1;
        UITableView* tableView2;
        UITableView* tableView3;
    }

    并且在你的 ViewController.m 中:

    -(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
    
    {
    
            if (tableView == tableView1)
            {
                //Your code
            }
            if (tableView == tableView2)
            {
                //Your code
            }
            if (tableView == tableView3)
            {
                //Your code
            }
        }
    2019-07-17 19:12:34
    赞同 展开评论
问答地址: