如何将参数传递给此函数? [英] How can I pass a parameter to this function?

查看:117
本文介绍了如何将参数传递给此函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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

- (void)replyAll:(NSInteger)tid {
// some code
}

如何将参数发送到 ReplyAll 函数?

How can I send a parameter to the ReplyAll function?

推荐答案

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

The replyAll method should accept (id)sender. If a UIButton fired the event, then that same UIButton will be passed as the sender. UIButton has a property "tag" that you can attach your own custom data to (much like .net winforms).

所以你要用以下方式连接你的事件:

So you'd hook up your event with:

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

然后处理:

(void) ReplyAll:(id)sender{
    NSInteger *tid = ((UIControl*)sender).tag;
    //...

这篇关于如何将参数传递给此函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆