繁体   English   中英

uibutton,把“目标”和“行动”

[英]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提供正确的框架属性,现在它有CGRectZero:

face.frame = CGRectMake( 0, 0, 30, 30 ); 

可可:框架和边界之间有什么区别?

我想到的第一件事是你正在为UIButton设置动作,但是你正在用UIButton的视图初始化UIBarButtonItem。 该操作未保存在视图中。 您尝试为UIBarButtonItem设置操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM