从主UIViewController类中分离UITableview数据源和委托的简单方法? [英] Simple way to separate UITableview datasource and delegate from main UIViewController class?

查看:65
本文介绍了从主UIViewController类中分离UITableview数据源和委托的简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

典型的UITableView使用模式是让主UIViewController成为它所持有的UITableView的目标数据源和委托。

The typical UITableView usage pattern is to have the main UIViewController become a target datasource and delegate for the UITableView it is holding on to.

有没有简单易行按照教程,这将有助于我弄清楚如何将与UITableViewDelegate和UITableViewDataSource方法相关的代码移动到一个单独的类,并将其挂钩到我的UIViewController?理想情况下,我希望将委托和数据源都放在同一个类中。

Are there any simple and easy to follow tutorials that would help me figure out how to move the code that pertains to the UITableViewDelegate and UITableViewDataSource methods into a separate class and hook that to my UIViewController instead? I would ideally like to have both the delegate and datasource living in the same class.

现在,我正在通过Interface Builder创建UITableView并将其插座连接到我的控制器class。

Right now, I am creating the UITableView via Interface Builder and connecting its outlet to my controller class.

典型代码:

@interface MyController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
    IBOutlet UITableview *myTableview;
}

我想做更多这样的事情:

I want to do something more like this:

@interface MyController : UIViewController 
{
    IBOutlet UITableview *myTableview;
}
@end

@interface MyTableSourceDelegate : NSObject<UITableViewDelegate, UITableViewDataSource>
{
}

@implementation MyTableSourceDelegate
    // implement all of the UITableViewDelegate and methods in this class 
@end


推荐答案

你会在这里找到一个非常相似的问题:

You'll find a very similar question answered here:

使用单独的委托/ dataSource时的UITableView问题

我想你会发现答案很有帮助。

I think you'll find the answers helpful.

这篇关于从主UIViewController类中分离UITableview数据源和委托的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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