我在特定视图控制器上有工具栏按钮,需要在其他视图控制器上消失。我能怎么做!!这是我的代码:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; //Initialize the toolbar toolbar = [[UIToolbar alloc] init]; toolbar.barStyle = UIBarStyleDefault; //Set the toolbar to fit the width of the app. [toolbar sizeToFit]; //Caclulate the height of the toolbar CGFloat toolbarHeight = [toolbar frame].size.height; //Get the bounds of the parent view CGRect rootViewBounds = self.parentViewController.view.bounds; //Get the height of the parent view. CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds); //Get the width of the parent view, CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds); //Create a rectangle for the toolbar CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight); //Reposition and resize the receiver [toolbar setFrame:rectArea]; //Create a button UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithTitle:@"Info" style:UIBarButtonItemStyleBordered target:self action:@selector(info_clicked:)]; [toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]]; //Add the toolbar as a subview to the navigation controller. [self.navigationController.view addSubview:toolbar]; //Reload the table view [self.tableView reloadData]; } - (void) info_clicked:(id)sender { //Initialize the Info View Controller if(ivControllerToolbar == nil) ivControllerToolbar = [[InfoViewController alloc] initWithNibName:@"InfoView" bundle:[NSBundle mainBundle]]; ivControllerToolbar.isViewPushed = NO; //Initialize the navigation controller with the info view controller if(infoNavController == nil) infoNavController = [[UINavigationController alloc] initWithRootViewController:ivControllerToolbar]; //Present the navigation controller. [self.navigationController presentModalViewController:infoNavController animated:YES]; }
我可以使用:
- (void)viewWillDisappear:(BOOL)animated {} - (void)viewDidDisappear:(BOOL)animated {}
? 我可能知道怎么做?
答案 0 :(得分:0)
我不知道你在viewWillAppear:
创建工具栏的原因。最好在viewDidLoad
或loadView
中创建视图层次结构(如果您没有使用xib创建视图)