2013-03-14 46 views

回答

0

一种可能性是创建一个自定义的UIButton,扩展包含你需要传递,在创建按钮时设置按钮的那个属性,然后访问它的动作被称为后的所有属性界面。例如:

@interface UIButton (additions) 

@property NSString * customPropertyString; 

@end 

然后,添加目标和选择的通常方式:

[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; 

最后,该处理方法的实现:

- (void)buttonPressed:(id)sender 
{ 
    UIButton * senderButton = (UIButton *)sender; 
    NSLog(@"%@", senderButton.customPropertyString); 
} 
1

如果你想传递对于UIButton多个arugment你应该通过一个Dictionary arugment

有2种方式处理:

  1. 您可以使用一个实例变量来保存您要使用的值。

例如:

- (void)buttonPressed:(id)sender 
{ 
    NSMutableDictionary *argDictionary = _ivar; 
} 

2.You可以使用类别伪造的属性。

如何捏造类别的属性,你可以看到:http://oleb.net/blog/2011/05/faking-ivars-in-objc-categories-with-associative-references/

,然后你可以使用:

- (void)buttonPressed:(UIButton *)sender 
{ 
    // use sender.argDictionary to get your fake property 
} 

更多信息,你可以看到my answer before