0

我正在尝试将添加按钮推送到不同的视图控制器,但我没有使用情节提要。该按钮出现,但单击时不执行任何操作。这是我的代码:

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

有什么建议么?

4

1 回答 1

3

Target 应该是 viewcontroller,而不是 nil

 UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
        initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                             target:self
                                  action:@selector(pushLogin)];
于 2013-02-20T19:40:52.963 回答