objective c - my own subclass's delegate methods wrapping around UITextField's delegate methods is crashing my app -


i creating own subclass subclass of uiview uilabel , uitextfield in it.

so still want delegate methods of uitextfield function, created own protocol called mylabeledinputviewdelegate wraps around uitextfield's delegate methods in way:

-(bool)textfieldshouldreturn:(uitextfield *)textfield {     return [self.delegate inputviewshouldreturn:self]; } 

and since textfield property of instance of own class, of course set it's delegate this:

if (self.delegate) self.textfield.delegate = self; 

but however, seems if init mylabeledinputview delegate set nil, crashes reason.

am setting correctly or there missing? thank much!

my designated initializer this:

- (id)initwithframe:(cgrect)frame       titlerelativelength:(float)length       titletext:(nsstring *)text       titlebackgroundcolor:(uicolor *)color       titletextcolor:(uicolor *)textcolor       textfieldbgcolor:(uicolor *)textfieldbgcolor       textfieldtextcolor:(uicolor *)textfieldtextcolor       delegate:(id<wrlabeledinputviewdelegate>)delegate; 

the implementation this:

- (id)initwithframe:(cgrect)frame titlerelativelength:(float)length titletext:(nsstring *)text titlebackgroundcolor:(uicolor *)color titletextcolor:(uicolor *)textcolor textfieldbgcolor:(uicolor *)textfieldbgcolor textfieldtextcolor:(uicolor *)textfieldtextcolor {     self = [super initwithframe:frame];     if (self) {         // initialization code         self.titlerelativelength = length;         self.title = text;         self.titlebackgroundcolor = color;         self.titletextcolor = textcolor;         self.textfieldbackgroundcolor = textfieldbgcolor;         self.textfieldtextcolor = textfieldtextcolor;     }     return self; } 

which captures passed in properties, , set delegate of uitextfield in layoutsubviews instance of own class.

ok, see now, missed adding parameter implementation. add , you'll go. , self.delegate = delegate;

edit:

you should doing on wrapped delegate calls, (or time create own protocol)

if ([self.delegate respondstoselector:@selector(inputviewshouldreturn:)]) {     [self.delegate inputshouldreturn:self]; } 

if don't implement delegate method in listening class, crash unless ask object if responds first.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -