我的导航栏上有2个图标,但当我显示alertViewController
时,这些图标会改变其位置。
这些是我的偶像。
当我显示alertViewController
这是我的viewController
内容。
UIBarButtonItem *helpItem;
UIBarButtonItem *helpItem1;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self setup];
}
-(void)setup{
helpItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(helpButtonItemTapped:)];
helpItem1 = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(helpButtonItemTapped:)];
helpItem.image = [UIImage imageNamed:@"test"];
helpItem1.image = [UIImage imageNamed:@"test"];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects: helpItem, helpItem1, nil];
}
-(void)helpButtonItemTapped:(id)sender{
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"Title"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet
];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
]];
[self presentViewController:alertController animated:YES completion:nil];
}
答案 0 :(得分:1)
将init UIBarbuttonItem代码更改为此
helpItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"memoAccess"] style: UIBarButtonItemStylePlain target:self action:@selector(helpButtonItemTapped:)];
helpItem1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"memoAccess"] style: UIBarButtonItemStylePlain target:self action:@selector(helpButtonItemTapped:)];
截图
答案 1 :(得分:0)
我遇到了同样的问题,但在Swift 3中,这就是我设法修复它的方法。我更改了以下代码:
let BarButtonItemVariable : UIBarButtonItem!
BarButtonItemVariable = UIBarButtonItem(title: "", style: .plain, target: self, action: #selector(self.SomeMethod))
BarButtonItemVariable.image = UIImage(named: "SomeImage")
self.navigationItem.rightBarButtonItem = BarButtonItemVariable
对此:
let BarButtonItemVariable : UIBarButtonItem = UIBarButtonItem(image: UIImage(named : "SomeImage"), target: self, style: .plain, action: #selector(self.SomeMethod))
self.navigationItem.rightBarButtonItem = BarButtonItemVariable