[英]Add a button to the left side of navigation bar on Xcode
我想在导航栏的左侧创建一个按钮,单击该按钮后,用户将被带到另一个页面。 但是我无法使其工作。 下面是我的代码。 请帮忙!
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelEdit:)];
尝试这个。
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]
initWithTitle:@"Left"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(leftItemAction)];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]
initWithTitle:@"Right"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(rightItemAction)];
self.navigationItem.rightBarButtonItem = rightItem;
self.navigationItem.leftBarButtonItem = leftItem;
- (void)leftItemAction
{
...
}
- (void)rightItemAction
{
...
}
我已经使用此代码添加了保存按钮
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setBackgroundImage:[UIImage imageNamed:@"save.png"] forState:UIControlStateNormal];
button2.frame = CGRectMake(0, 0, 100, 31);
[button2 addTarget:self action:@selector(onSave:) forControlEvents:UIControlEventTouchUpInside];
saveButton = [[UIBarButtonItem alloc]initWithCustomView:button2];
self.navigationItem.leftBarButtonItem = saveButton;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.