簡體   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