When to use a colon with a @selector

前端 未结 6 1232
傲寒
傲寒 2020-12-03 04:10

Just getting going with iPhone development and Objective-C.

Yesterday I was trying to addObserver for a notification in a view of mine, and I kept getti

6条回答
  •  死守一世寂寞
    2020-12-03 04:15

    You seem to be missing one concept here: colon is, in some way, a part of the method name. E.g., method

    -(IBAction) doIt:(id)sender;
    

    has name doIt:. Thus, colon should be used to reference this method.
    But this method doesn't have a colon at the end

    -(IBAction) doItWithoutParameter;
    

    Same goes for methods accepting multiple arguments, they have names like doItWithParam1:andParam2:

提交回复
热议问题