objective c - How to stop warning for UIView may not respond to selector -
i have class has uiview property. pass in uilabel; uitextfield. no matter pass in, want class set text. doing this, works:
if ([self.viewtoupdate respondstoselector:@selector(settext:)] && !self.newanswer) [self.viewtoupdate settext:[[self.choices objectatindex:indexpath.row] text]]; the problem is, gives warning, because though i'm checking respondstoselector, xcode doesn't know uiview respond settext:. how can remove warning?
i know can check see if it's textfield or label, , cast textfield or label, respectively, pain, , if ever have more types of views, i'd have add few more lines of code each one.
i thought creating own protocol, , having class have id type viewtoupdate... of course uitextfield , uilabel wouldn't conform protocol...
try casting id:
if ([self.viewtoupdate respondstoselector:@selector(settext:)] && !self.newanswer) [(id)self.viewtoupdate settext:[[self.choices objectatindex:indexpath.row] text]];
Comments
Post a Comment