iphone - Calling a SuperClass's DataSource? -
i working on simple slot machine. sub-classed uipickerview. pickerview datasource don't need define in controller, because 5. can define in subclass so?
@interface slotmachineview : uipickerview <uipickerviewdatasource> {
}
@end
#import "slotmachineview.h" @implementation slotmachineview - (id)init{ if ((self = [super init])) { super.datasource = self; } return self; } - (nsinteger)numberofcomponentsinpickerview:(uipickerview *)pickerview{ return 5; } - (nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component{ return 5; } - (void)dealloc { [super dealloc]; } @end
yes, can. can write self.datasource = self
, because super
, self
same object*. remember, object instance of superclass instance of class it's declared as. has same properties , responds same messages.
*the difference between super
, self
super
skips on methods defined in current class.
Comments
Post a Comment