[英]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.