Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS Objective-C UIBarButtonItem集选择器_Ios_Objective C - Fatal编程技术网

iOS Objective-C UIBarButtonItem集选择器

iOS Objective-C UIBarButtonItem集选择器,ios,objective-c,Ios,Objective C,我正在创建一个UIBarButtonItem来创建一个后退按钮: self.backButton = [[UIBarButtonItem alloc] initWithCustomView:backToolbar]; self.backButton.enabled = YES; self.backButton.imageInsets = UIEdgeInsetsZero; 我想将其选择器设置为: - (IBAction)goBack:(id)sender { NSLog(@"goBac

我正在创建一个UIBarButtonItem来创建一个后退按钮:

self.backButton = [[UIBarButtonItem alloc] initWithCustomView:backToolbar];
self.backButton.enabled = YES;
self.backButton.imageInsets = UIEdgeInsetsZero;
我想将其选择器设置为:

- (IBAction)goBack:(id)sender {
    NSLog(@"goBack pushed");

    [self.iframeView goBack];
}
将backButton设置为具有
goBack
选择器的最佳方法是什么

编辑:


一种方法是直接分配给工具栏按钮项,如

[backButton setTarget:self];
[backButton setAction:@selector(backButtonPressed:)];
第二种方式:启动带有按钮的条形按钮项,该按钮已具有操作

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 60.0, 30.0)];
[button addTarget:self
           action:@selector(backButtonPressed:)
 forControlEvents:UIControlEventTouchUpInside];
self.backButton = [[UIBarButtonItem alloc] initWithCustomView:button];

什么是backToolBar?UILabel/UIButton?更新了我的问题。这只是一个UIBarButtonItem有什么理由把
backButton
(已经是一个条形按钮)传递给另一个
UIBarButtonItem
?你做过类似于
[[uibarbuttoneim alloc]initWithTitle:@“Back”样式:uibarbuttoneimstyleplain目标:@selector(self)action:@selector(goBack:)]简单地将
操作
属性设置为
@selector(goBack:)
有什么错?
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 60.0, 30.0)];
[button addTarget:self
           action:@selector(backButtonPressed:)
 forControlEvents:UIControlEventTouchUpInside];
self.backButton = [[UIBarButtonItem alloc] initWithCustomView:button];