开发者

Subclassing - uiviewcontrollers: where could I find some examples?

I'm a little bit confused about the custom UiViewController inheritance.

For example if I have:

    @interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
       IBOutlet UITableView *tableView;

           id <MyDelegate> aDelegate;
           AnObject *myObject;
    }

    @property (开发者_C百科nonatomic, assign) id <MyDelegate> aDelegate;
    @property (nonatomic, retain) AnObject *myObject;

    @end

A subclass of MyViewController "inherits" the protocol declaration? that is, can or not it override the methods in them, setting the delegate and datasource properly without redeclaring in its interface?

And what about property and their possible deallocation?

I would some examples, links...


Firstly, a protocol is simply a promise that a class implements required and (optionally) optional methods. That's all it is. You can override these in subclasses and such however you want.

The data source and delegate of the table view are set to self, and self implements the UITableViewDataSource and UITableViewDelegate protocols.

In your sub-class, self is the sub-class. Overriding the protocol methods in the sub-class will work perfectly fine. The table view is the one defined in the parent class.

In short, the answer is yes. If you want more information I suggest you read up on how @protocol works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜