Zhe*_*hen 8 cocoa-touch arguments objective-c selector ios
我怎样才能在@selector下面的代码中传递一个参数?
[thisIconBtn addTarget:self action:@selector(changeIconState) forControlEvents:UIControlEventTouchUpInside];
-(void)changeIconState:(UITableViewCell*)thisCell
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
首先,冒号是选择器的一部分:@selector(changeIconState:).
其次,操作是采用一组特定参数的方法 - 您不能仅使用任何方法作为操作.通常,操作如下所示:
- (void)myAction:(id)sender;
Run Code Online (Sandbox Code Playgroud)
其中sender是指向发送操作的对象的指针.在您的代码中,当点击thisIconButton时,该按钮将作为发件人传递.