[英]uibutton, put “target” and “action”
我有以下代码在UIToolbar(postoInfo)上添加UIBarButtonItem类型的按钮:
UIImage *faceImage = [UIImage imageNamed:@"informazioni.png"];
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];
[face addTarget:self action:@selector(press:) forControlEvents:UIControlEventTouchUpInside];
face.bounds = CGRectMake( 0, 0, 30, 30 );
[face setImage:faceImage forState:UIControlStateNormal];
buttonOne = [[UIBarButtonItem alloc] initWithCustomView:face];
NSArray *buttons = [NSArray arrayWithObjects: buttonOne, nil];
[postoInfo setItems: buttons animated:YES];
按下按钮时我会调用一个方法,我添加了以下行,但不起作用:
[face addTarget:self action:@selector(press:) forControlEvents:UIControlEventTouchUpInside];
我想到的第一件事是你正在为UIButton设置动作,但是你正在用UIButton的视图初始化UIBarButtonItem。 该操作未保存在视图中。 您尝试为UIBarButtonItem设置操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.