我的导航栏上有两个按钮。一个在左边,一个在右边。左边的按钮有效,但右边的按钮无效。如果我交换按钮,重新编译并加载问题仍然存在,无论哪个按钮位于栏的正确位置。
此外,当我尝试使用右键时,左键会立即工作,但左键也会停止工作。
如何使右键起作用?下面是代码。
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