iOS 有個compiler driective 叫做@selector 用黎send message 比target
From Documentation
In Objective-C, selector has two meanings. It can be used to refer simply to the name of a method when it’s used in a source-code message to an object.
例如有個UIButton
UIBarButtonItem *moveButton = [[UIBarButtonItem alloc] initWithTitle:@"Move" style:UIBarButtonItemStyleBordered target:self action:@selector(toogleMove)];
target:self > 即係自己呢個class
toogleMove 係message name
- (IBAction)toogleMove{
...
}
如果想call既messge 有parameter 咁會變成 action:@selector(toogleMove:)
無parameter 就會唔好手多加 : 唔係compiler 搵唔到你想call message
P.S. 如果個message 有parameters
[friend performSelector:@selector(gossipAbout:) withObject:aNeighbor];
沒有留言:
張貼留言