我以编程方式从UIButton创建了2个UIBarButtonItem。导航控制器位于UITabBar中。当我移动到同一个UITabBar中的另一个控制器时,这两个UIBarButton不会被移除。任何人都知道如何删除这两个UIBarButtonItem
- (void)viewWillAppear:(BOOL)animated {
// Left Tab Bar Items
UIButton *fbutton = [[UIButton alloc] init];
[fbutton setImage:[[UIImage imageNamed:@"ble"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[fbutton addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
fbutton.frame=CGRectMake(0, 0, 48 , 48);
UIBarButtonItem *fBLEItem = [[UIBarButtonItem alloc] initWithCustomView:fbutton];
fBLEItem.enabled = NO;
UIButton *tbutton = [[UIButton alloc] init];
[tbutton setImage:[[UIImage imageNamed:@"ble"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[tbutton addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
tbutton.frame=CGRectMake(0, 0, 48, 48);
UIBarButtonItem *tBLEItem = [[UIBarButtonItem alloc] initWithCustomView:tbutton];
tBLEItem.enabled = NO;
self.tabBarController.navigationItem.leftItemsSupplementBackButton = YES;
self.tabBarController.navigationItem.leftBarButtonItems = @[fBLEItem,tBLEItem];
}
- (void) viewWillDisappear:(BOOL)animated {
[self.navigationItem setLeftBarButtonItem:nil animated:NO];
[self.navigationItem setRightBarButtonItem:nil animated:NO];
}
答案 0 :(得分:0)
您在UIBarButtonItem
上设置self.tabBarController.navigationItem
,但在nil
上设置self.navigationItem
。这是两件不同的事情。尝试:
[self.tabBarController.navigationItem setLeftBarButtonItem:nil animated:NO];
[self.tabBarController.navigationItem setRightBarButtonItem:nil animated:NO];