我的导航栏上有两个按钮。一个在左边,一个在右边。左侧的按钮有效,但右侧的按钮无效。如果我交换按钮,重新编译并加载问题仍然存在右侧按钮,无论哪个按钮位于条形图的正确位置。
此外,当我尝试使用右按钮时左按钮工作,左按钮也停止工作。
如何使右键工作?以下是代码。
UINavigationBar *NavBar = [[UINavigationBar alloc] init];
[NavBar sizeToFit];
[self.view addSubview:NavBar];
UIBarButtonItem *cmdBack = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(cmdBackClicked:)];
UIBarButtonItem *cmdAddDevice = [[UIBarButtonItem alloc] initWithTitle:@"Add Device"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(cmdAddDeviceClicked:)];
UINavigationItem *NavBarItems = [[UINavigationItem alloc] initWithTitle:@"Settings"];
NavBarItems.leftBarButtonItem = cmdBack;
NavBarItems.rightBarButtonItem = cmdAddDevice;
NavBar.items = [NSArray arrayWithObjects:NavBarItems, nil];
按钮的功能是这些
- (void) cmdBackClicked:(id)sender
{
[self.view removeFromSuperview];
}
- (void) cmdAddDeviceClicked:(id)sender
{
vcAddDevice *ViewAddDevice = [[vcAddDevice alloc] initWithNibName:@"vcAddDevice" bundle:nil];
[ViewAddDevice SetEditDeviceMode:[NSString stringWithFormat:@"No"]];
[self.view addSubview:ViewAddDevice.view];
}
在.h文件中我有这个。
#import <UIKit/UIKit.h>
#import "vcAddDevice.h"
@interface ViewControllerSettings : UIViewController<vcAddDeviceControllerDelegate, UITableViewDelegate, UITableViewDataSource>
- (IBAction) cmdBackClicked:(id) sender;
- (IBAction) cmdAddDeviceClicked:(id) sender;
@end