English 中文(简体)
用户按钮, 设定“ 目标” 和“ 动作 ”
原标题:uibutton, put "target" and "action"

我有以下代码,在 UIToolbar (postoInfo) 上添加一个类型 UIBarbutton 的按钮 :

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];

I would call a method when the button is pressed, I added, the following line, but does not work:

[face addTarget:self action:@selector(press:) forControlEvents:UIControlEventTouchUpInside];
最佳回答

您应该为 UIButton 提供正确的框架属性, 现在它有 CGRect Zero :

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

Cocoa:框架和界限之间有什么区别?

问题回答

我首先想到的是 您正在设置 UI 按钮的动作, 但是您正在以 UI 按钮的视图来初始化 UI BarButtonTroup 。 该动作没有保存在视图中 。 您尝试为 UI BarButton Text 设定动作 。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签