通过方法传递 2 个对象 - iPhone SDK
我有一个“观察者”,它监视 UISwitch 值的变化:
[cell.switcher addTarget:self action:@selector(switched:withName:) forControlEvents:UIControlEventValueChanged];
当值更改时,调用此方法:
-(void)switched:(UISwitch *)switcher withName:(NSString *)name;
如您所见,我有两个对象,需要通过第一个代码传递。如何通过 addTarget:action:forControlEvents 方法发送 nsstring 和 uiswitch 的对象,以便我可以在选择器 Switched:withname 中访问它们?
谢谢,
Kevin
编辑:我不太擅长 obj-c 并且没有真正正确地学习这些术语,所以如果我犯了错误,请告诉我!
I have this "observer" that watches the UISwitch for a change in value:
[cell.switcher addTarget:self action:@selector(switched:withName:) forControlEvents:UIControlEventValueChanged];
When the value is changed this method is called:
-(void)switched:(UISwitch *)switcher withName:(NSString *)name;
As you can see I have two objects which I need to pass with the first code. How do I send the object of a nsstring and a uiswitch through the method of addTarget:action:forControlEvents so that I can access them in the selector switched:withname?
Thanks,
Kevin
EDIT: I'm not very good with obj-c and didn't really learn the terms correctly, so if I made a mistake please let me know!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的方法是标记你的 UISwitch 对象:
然后在你的
switched:
方法中,你可以测试发送者的标签并在那里定义你的字符串:Best way to go about this is to tag your UISwitch objects:
Then on your
switched:
method you can test the sender's tag and define your string there:你不能。 UIControl 操作的选择器只会传回发送者(在本例中为您的 cell.switcher)。您应该找到一种方法来根据操作和发件人的 ID 来识别您需要哪个字符串。
You can't. The selector for UIControl actions will only pass back the sender (in this case, your cell.switcher). You should find a way to identify which string you need based on the action and the id of the sender.