Objective c UIBarButtonim未调用操作方法

Objective c UIBarButtonim未调用操作方法,objective-c,ios7,xcode5,uinavigationbar,uinavigationitem,Objective C,Ios7,Xcode5,Uinavigationbar,Uinavigationitem,我正在使用此代码添加导航栏按钮 UIColor *green = [UIColor colorWithRed:0.1 green:0.7 blue:0.2 alpha:1.0]; self.navigationItem.rightBarButtonItem = [KHFlatButton barButtonWithTitle:@"Go Pro!" backgroundColor:green]; self.navigationItem.rightBarButtonItem.action =@sel

我正在使用此代码添加导航栏按钮

UIColor *green = [UIColor colorWithRed:0.1 green:0.7 blue:0.2 alpha:1.0];
self.navigationItem.rightBarButtonItem = [KHFlatButton barButtonWithTitle:@"Go Pro!" backgroundColor:green];
self.navigationItem.rightBarButtonItem.action =@selector(goProButtonTapped);
按钮显示,但它不调用其操作方法

- (void) goProButtonTapped
{
    NSLog(@"Go Pro button Tapped");
}

求求你,救命

您还应该设置目标:

self.navigationItem.rightBarButtonItem.target = self;
也可以使用自定义视图创建条形按钮项:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIColor *green = [UIColor colorWithRed:0.1 green:0.7 blue:0.2 alpha:1.0];
button.backgroundColor = green;
[button addTarget:self action:@selector(goProButtonTapped) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Go Pro!" forState: UIControlStateNormal];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];

尝试用目标和操作初始化按钮。不工作。你能提供代码来添加带有背景颜色和操作方法的navigationbar项目按钮吗。使用此代码可以调用操作,但bg颜色不会显示。我最后添加了按钮背景图像。您可以尝试使用setBackgroundImage:forState:method。