添加一个按钮
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UITabBarSystemItemContacts target:self action:@selector(clickSettings:)]; self.navigationItem.rightBarButtonItem = rightButton;
新版本xcode不用release
添加两个按钮
UIToolbar* toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 45)]; [toolBar setTintColor:[self.navigationController.navigationBar tintColor]];
[toolBar setAlpha:[self.navigationController.navigationBar alpha]];
NSMutableArray* buttonArray = [[NSMutableArray alloc] initWithCapacity:2];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(clickSettings:)];
UIBarButtonItem *rightButton2 = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UITabBarSystemItemContacts target:self action:@selector(clickEdit:)];
[buttonArray addObject:rightButton];
[buttonArray addObject:rightButton2];
[toolBar setItems:buttonArray animated:NO];
UIBarButtonItem *barBI = [[UIBarButtonItem alloc] initWithCustomView:toolBar];
self.navigationItem.rightBarButtonItem = barBI;