推送UIBarButtonSystemItem添加到其他视图控制器

时间:2013-02-20 19:38:21

标签: ios objective-c uiviewcontroller uinavigationcontroller

我正在尝试将添加按钮推送到其他视图控制器而我没有使用故事板。按钮出现但单击时不执行任何操作。这是我的代码:

-(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;
}

有什么建议吗?

1 个答案:

答案 0 :(得分:3)

目标应该是viewcontroller,而不是nil

 UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
        initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                             target:self
                                  action:@selector(pushLogin)];