iphone - IOS button pressed event? -


i'm know difference between:

- (ibaction)operationpressed:(uibutton *)sender {  } 

and:

- (ibaction)operationpressed:(id)sender {   } 

i can see xcode try put more auto complete when using id. 1 correct use , why?

thanks

technically, not matter: declared type of uibutton* not guarantee calls objects of other types impossible. fitst style lets access properties of uibutton "dot syntax", while second style lets reuse handler other ui objects without making readers wonder going on.

for example, if know event handler used buttons, can declare type of sender uibutton, , this:

- (ibaction)operationpressed:(uibutton *)sender {     sender.adjustsimagewhenhighlighted = yes; } 

with second declaration have write this:

- (ibaction)operationpressed:(id)sender {     [sender setadjustsimagewhenhighlighted:yes]; } 

on other hand, if plan reuse handler different ui objects, second approach preferable.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -