将parameter passing给@selector方法
我在表格视图中添加了一个UIButton
。 现在,当我点击一个特定的button,我需要获取该行对应的对象的细节。
[button addTarget:self action:@selector(invite:contactmail:) forControlEvents:UIControlEventTouchUpInside];
我已经使用这个button的方法; 我怎么能传递参数给这个select器方法? 还是有任何其他的方式来传递参数,当这个button被点击这个方法?
作为动作添加到UIControl的方法可以有3个不同的签名
- (void)action - (void)action:(id)sender - (void)action:(id)sender event:(UIEvent *)event
你不能传递你自己的对象。 在发送者(你的button)对象的帮助下,通常可以得到你想传递的任何对象。
如果你在tableviewcell中有一个button,你可以使用像这样的东西来获得单元格的索引path。
- (IBAction)buttonAction:(id)sender { UIButton *button = (UIButton *)sender; CGPoint buttonOriginInTableView = [button convertPoint:CGPointZero toView:tableView]; NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:buttonOriginInTableView]; // do something }
和indexPath你可以得到你需要的对象。
不,不是真的。 点击事件是
-(IBAction) fnc:(id)sender;
如果你想调用另一种方法,你需要这样做的formsfunction。
-(IBAction) fnc:(id) sender { UIButton *b = (UIButton*) sender; [self otherFnc:b arg:arg1 arg2:arg2]; }