Add items to NavigationBar (Not using UINavigationController)

后端 未结 5 513
北恋
北恋 2020-12-31 13:07

I have a UIViewController with a UITableView in it, and also added a UINavigationBar. How can I add and \"edit\" button and a \"+\" button in that bar programmatically? (I h

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-31 13:51

    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(theEditMethod:)];      
    [viewController.navigationItem setLeftBarButtonItem:leftBarButton animated:NO];
    [leftBarButton release];
    
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(theAddMethod:)];       
    [viewController.navigationItem setLeftBarButtonItem:rightBarButton animated:NO];
    [rightBarButton release];
    

提交回复
热议问题