开发者

How to remove (pop) a view from OTHER view?

I have 2 views. One is the 'viewheader' and the other is the 'viewContent' (added as subview).

'viewCon开发者_StackOverflow中文版tent' contains a TableView (based on UINavigationController) and the TableView can drill down to a DetailView (UIViewController). (see Image below)

My Question is: How can I remove (pop) the DetailView, with a UIButton FROM the 'headerView'.

The goal is to create a fixed Navigation, and only change (animate) the lower Content.

Thanks

// add "fixed" Header
- (void)loadView {
    viewHeader = [[HeaderViewController alloc] initWithNibName:@"HeaderViewController" bundle:nil];
    self.view = viewHeader.view;
}

// add content view
- (void)viewDidLoad {
    [super viewDidLoad];

    viewContent = [[MainContentViewController alloc] initWithNibName:@"MainContentViewController" bundle:nil];

    CGRect viewFrame = CGRectMake(0.0f, 164.0f, 320, 316);
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewContent];
    [navController setNavigationBarHidden:YES];
    [navController.view setFrame:viewFrame];
    viewHeader.contentNavView = navController; // <<<< CAN'T POP THE VIEW by passing UINavigationController to "header view"
    [self.view addSubview:navController.view];
}


You must somehow send a removeFromSuperview message to the detail view when the button on the header view is tapped (i.e. an IBAction is triggered). You can achieve this by either making the detail view a property of the header view controller to be able to call the removeFromSuperview of the detail view in your header view's IBAction. Or if you prefer loose coupling (which you should), post a notification from the IBActionin the header view and register for that notification in the detail view with a method that removes the detail view from the header view.


I Found my mistake. The definition of 'contentNavView' inside 'viewheader' was wrong

Changed it from UIViewController to UINavigationController.

@interface HeaderViewController : UIViewController {
    UINavigationController *contentNavView;
}
...

Calling

[contentNavView pushViewController:aViewController animated:NO];

works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜