我想在导航栏的左侧创建一个按钮,单击它后,用户将被带到另一个页面。但是我无法让它工作。下面是我的代码。请帮忙!
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelEdit:)];
我想在导航栏的左侧创建一个按钮,单击它后,用户将被带到另一个页面。但是我无法让它工作。下面是我的代码。请帮忙!
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;