我正在尝试将添加按钮推送到其他视图控制器而我没有使用故事板。按钮出现但单击时不执行任何操作。这是我的代码:
-(void)pushLogin
{
[self.navigationController pushViewController:[[AddListingViewController alloc] init] animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Listings";
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:nil
action:@selector(pushLogin)];
self.navigationItem.rightBarButtonItem = addButton;
}
有什么建议吗?
答案 0 :(得分:3)
目标应该是viewcontroller,而不是nil
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(pushLogin)];