iphone - When to use a colon with a @selector -
just getting going iphone development , objective-c.
yesterday trying addobserver notification in view of mine, , kept getting error:
unrecognized selector sent instance
i tracked down fact needed include trailing colon selector argument:
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(nameofmyselector:) name:@"bblocationservicesaredisabled" object:nil];
today, thought clever because when setting action argument button, remembered mistake yesterday, , added colon action argument. action argument takes @selector, selector argument while setting observer nsnotification, figured doing right thing.
however, following code:
[self.calltoactionbutton addtarget:self action:@selector(nameofmyselector:) forcontrolevents:uicontroleventtouchupinside];
i exact same error:
unrecognized selector sent instance
what gives? why 1 @selector require trailing colon, , other doesn't? rules should follow when should included , when should left off, , why can't 1 or other?
thanks!
as mentioned boltclock, character referring colon. difference between @selector(method)
, @selector(method:)
method signature. 2nd variant expects parameter passed.
@selector(method)
expect method: -(void)method
@selector(method:)
expect method: -(void)method:(id)someparameter
Comments
Post a Comment