UITableView superClass for delegate?

Quick question. I am setting a delegate for a UITableView and I have a question regarding setting the delegate and dataSource properties. I noticed that the properties for the delegate and dataSource are not available, I thought that adopting the protocols would make them available. But now I think I might have a superclass class for my delegate class.

I currently have:

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

      

My interface for TestDelegate looks like this:

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

      

May I ask if it should be:

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

      

Gary

EDIT: I think this might be on the right track: my superClass delegate must be an NSObject, I also have a UITableView in the Interface Builder.

I added @property (non-atomic, keep) IBOutlet UITableView * myTableView; in Xcode and linked this to my UITableView in IB. I can now access the delegate and dataSource properties in Xcode via IBOutlet.

+2


a source to share


1 answer


No , there is a difference between subclassing UITableView

and simply conforming to protocols UITableViewDelegate

or UITableViewDatasource

.

You want to subclass UITableView

if you need different behavior in the table view itself. In most cases, you will not want to do this .



UITableView

has a property delegate

and dataSource

, you can assign it to an object that conforms to the corresponding protocol.

If you want top-level access to properties delegate

and dataSource

, you need to subclass UITableViewController

.
(disagree with delegate protocols if you subclass UITableViewController

)

+3


a source







All Articles