在视图控制器中使用多个 tableview 时使用委托方法 [英] Use delegate methods when using multiple tableviews in a view controller

查看:38
本文介绍了在视图控制器中使用多个 tableview 时使用委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想在一个 ViewController 中使用 3 个 tableview.问题是我如何单独使用 UITableViewDelegate 方法.例如;我可以通过标记为每个 UITableView 单独使用 cellForRowAtIndexPath 方法.但是,我不知道如何为每个 tableview 使用 numberOfRowsInSectionnumberOfSectionsInTableView 方法.可能吗?

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
    }
}

这篇关于在视图控制器中使用多个 tableview 时使用委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆