Sus*_*cob 2 iphone xcode objective-c
鉴于你有一个方法
-(void)aSelector:(id)anyArgument;
Run Code Online (Sandbox Code Playgroud)
并以编程方式设置了UIButton
UIButton *myButton = [[UIButton alloc] init]
Run Code Online (Sandbox Code Playgroud)
好吧,我明白当你创建一个UIButton时,你必须使用这个方法
[myButton addTarget:nil action@selector(aSelector:) for ControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
但是我在哪里通过论证?我知道通常,你会使用
[myButton withObject:anyArgument];
Run Code Online (Sandbox Code Playgroud)
但NSControl不允许这样做,但有可能因为选择器名称后的冒号表示如此.
通常,-aSelector:将被定义为这样
- (void) aSelector:(id)sender
{
NSLog(@" sender = %@", sender);
}
Run Code Online (Sandbox Code Playgroud)
而论证将是myButton.请记住,您可能有几个按钮都调用方法-aSelector:然后,您需要在运行时区分哪个是调用方(发送方).
| 归档时间: |
|
| 查看次数: |
1912 次 |
| 最近记录: |