-1

我有一个SEL要在按钮选择器中设置的变量。

我的代码是这样的:

GridView *ObjGridView=[[GridView alloc]initWithFrame:frame]; 
[[NSBundle mainBundle ] loadNibNamed:@"GridView" owner:ObjGridView options:nil];

CATEGORY *ObjCategory=[arrCategory objectAtIndex:index];
//do something 

ICON *ObjIcno=[ObjCategory.arrIconObjects objectAtIndex:indexIcon];

[ObjGridView.button1 addTarget:self action:ObjIcno.handler forControlEvents:UIControlStateNormal];

ObjIcno.handler是一个 SEL 变量(之前由选择器设置)

像这样:

arrSectonProductivityTools=[NSMutableArray arrayWithObjects:[[[ICON alloc]initWithIcon:@"firefox.png":@"Firefox":@selector(FirefoxCickEvent:)] autorelease],nil];

我以这种方式在我的班级中设置了选择器,设置正确,但我没有收到点击事件。

4

1 回答 1

1
[ObjGridView.button1 addTarget:self action:ObjIcno.handler forControlEvents:UIControlStateNormal];

应该:

[ObjGridView.button1 addTarget:self action:ObjIcno.handler forControlEvents:UIControlEventTouchUpInside];

要获得除 UIControlEventTouchUpInside 之外的更多选项,请执行 cmd+鼠标单击 UIControlEventTouchUpInside。

于 2012-05-29T13:35:04.847 回答