UINavigationBar UIBarButtonItem works on left but not on right
I have two buttons on my navbar. One on the left and one on the right. The
button on the left works but the one on the right does not work. If I swap
the buttons, recompile and load the issue persist with the right button
regardless of which button is in the right spot of the bar.
Also while the left button works as soon as I try to use the right button
the left button stops working too.
How do I make the right button work? Below is the code.
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];
The functions for the buttons are these
- (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];
}
In the .h file I have this.
#import <UIKit/UIKit.h>
#import "vcAddDevice.h"
@interface ViewControllerSettings :
UIViewController<vcAddDeviceControllerDelegate, UITableViewDelegate,
UITableViewDataSource>
- (IBAction) cmdBackClicked:(id) sender;
- (IBAction) cmdAddDeviceClicked:(id) sender;
@end
No comments:
Post a Comment