I added a toolBar with this code:
- (void)viewWillAppear:(BOOL)animated {
UIBarButtonItem *yesterday = [[UIBarButtonItem alloc]initWithTitle:@"Yesterday"
开发者_运维问答 style:UIBarButtonItemStyleBordered target:self action:@selector(yesterday:)];
UIBarButtonItem *today = [[UIBarButtonItem alloc]initWithTitle:@"Today"
style:UIBarButtonItemStyleDone target:self action:@selector(today:)];
UIBarButtonItem *tomorrow = [[UIBarButtonItem alloc]initWithTitle:@"Tomorrow"
style:UIBarButtonItemStyleBordered target:self action:@selector(tomorrow:)];
UIBarButtonItem *month = [[UIBarButtonItem alloc]initWithTitle:@"Month"
style:UIBarButtonItemStyleBordered target:self action:@selector(month:)];
NSArray *items = [NSArray arrayWithObjects:yesterday,today,tomorrow,month, nil];
[yesterday release];
[today release];
[tomorrow release];
[month release];
UIToolbar *toolbar = [[UIToolbar alloc] init];
[toolbar sizeToFit];
[toolbar setFrame:CGRectMake( 0, 20, 320, 40)];
[toolbar setItems:items];
[self.navigationController.view addSubview:toolbar];
}
but when i change the view using the navigation controller the toolbar stays there...
how can i remove that subview?
UINavigationController has a toolbar built in which is hidden by default. You can display it using [navigationController setNavigationBarHidden:animated:];
. You might want to use that instead. Then, before you push a view controller, set that view controller's hidesBottomBarWhenPushed property to true.
The reason your toolbar doesn't go away in this instance is that you're adding it to navigationController's view which displays on top of other views it controls. You could instead add it as a subview of self.
To answer your specific question, though, to remove the toolbar from any superview, use [toolbar removeFromSuperview]
. In this case, I would go with the cleaner solution of using the toolbar that is built into navigation controllers.
精彩评论