UITableView的superClass为委托? [英] UITableView superClass for delegate?

查看:105
本文介绍了UITableView的superClass为委托?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个快速的问题,我为UITableView设置一个委托,我有一个关于设置delegate和dataSource属性的问题。我注意到delegate和dataSource的属性不可用,我认为采用协议将使它们可用。但我现在认为我可能有我的委托类的超类错了。

A quick question, I am setting a delegate for UITableView and I have a question regarding setting the delegate and dataSource properties. I have noticed that the properties for delegate and dataSource are not available, I was thinking that adopting the protocols would make them available. But I am now thinking that I maybe have the superclass for my delegate class wrong.

目前我有:

-(void)viewDidLoad {
    TestDelegate *tempDelegate = [[TestDelegate alloc] init];
    [self setMyDelegate:tempDelegate];
    // setDelegate
    // setDataSource
    [tempDelegate release];
    [super viewDidLoad];
}

我的TestDelegate界面如下:

My interface for TestDelegate looks like:

@interface TestDelegate : NSObject <UITableViewDelegate, UITableViewDataSource> {
    NSArray *listData;
    int myCounter;
}

我可以问上面是否应该是:

Can I ask if the above should be:

@interface TestDelegate : UITableView <UITableViewDelegate, UITableViewDataSource> {
    NSArray *listData;
    int myCounter;
}

gary

EDIT:我认为它可能在正确的轨道上:我的委托的superClass应该是NSObject,我也有一个UITableView在接口生成器。

I think it might be on the right track: my delegate superClass should be NSObject, I also have a UITableView in Interface Builder.

我添加了@property(nonatomic,retain)IBOutlet UITableView * myTableView;在Xcode和连接到我的UITableView在IB。现在可以通过IBOutlet访问Xcode中的delegate和dataSource属性。

I have added @property(nonatomic, retain)IBOutlet UITableView *myTableView; in Xcode and connected this to my UITableView in IB. I can now access the delegate and dataSource properties in Xcode via the IBOutlet.

推荐答案

子类化 UITableView 和仅符合 UITableViewDelegate UITableViewDatasource 协议。

No, there is a difference between subclassing UITableView and merely conforming to the UITableViewDelegate or UITableViewDatasource protocols.

如果你需要不同的版本,你需要子类化 UITableView 行为在表视图本身。 - > 大多数时候你不会这样做

You would want to subclass UITableView if you needed different behavior in the table view itself. -> Most of the time you will not want to do this.

UITableView 具有委托 dataSource 属性,您可以将其分配给符合相应协议的对象。

UITableView has a delegate and dataSource property, you can assign it to an object that conforms to the respective protocol.

如果您想要访问委托 dataSource 属性,你需要子类 UITableViewController (不符合委托协议,如果你子类 UITableViewController

If you want to have top-level access to the delegate and dataSource properties, you need to subclass UITableViewController. (do not conform to the delegate protocols if you subclass UITableViewController)

这篇关于UITableView的superClass为委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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