如何将参数传递给此函数?

Vij*_*eta 10 iphone objective-c

我有以下代码:

[replyAllBtn addTarget:self.target action:@selector(ReplyAll:) forControlEvents:UIControlEventTouchUpInside];

- (void)replyAll:(NSInteger)tid {
// some code
}
Run Code Online (Sandbox Code Playgroud)

如何向ReplyAll函数发送参数?

Rob*_*sor 21

replyAll方法应该接受(id)发送者.如果UIButton触发了该事件,那么相同的UIButton将作为发件人传递.UIButton有一个属性"标记",您可以将自己的自定义数据附加到(很像.net winforms).

所以你要把你的活动挂钩:

[replyAllBtn addTarget:self.target action:@selector(ReplyAll:) forControlEvents:UIControlEventTouchUpInside];
replyAllBtn.tag=15;
Run Code Online (Sandbox Code Playgroud)

然后处理它:

(void) ReplyAll:(id)sender{
    NSInteger *tid = ((UIControl*)sender).tag;
    //...
Run Code Online (Sandbox Code Playgroud)