简体   繁体   中英

Pushing view controller from inner view controller

As explained in this question , I have a view controller that needs to replace itself with a different layout in certain cases where data may not be present. This seems to work:

if ([analysis length] == 0) {
    hasReview = NO;
    UnreviewedSPP* unreviewedSPPView = [[UnreviewedSPP alloc] init];
    unreviewedSPPView.ProductName = self.productName;
    unreviewedSPPView.SdcId = self.sdcId;
    unreviewedSPPView.Delegate = self;
    NSArray* newViews = [[NSBundle mainBundle] loadNibNamed:@"UnreviewedSPP" owner:unreviewedSPPView options:nil];
    self.view = [newViews objectAtIndex:0];
    return;
}

However, it seems that I cannot push a new view controller from within the replacement view:

    [priceButton handleControlEvent:UIControlEventTouchUpInside withBlock:^{
        WebViewController* wv = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil] autorelease];
        wv.url = offerURL;
        [Delegate performSelector:@selector(pushViewControllerFromSubview:) withObject:wv];
    }];

priceButton is a custom button object that can perform a block as a target action.

I've tried multiple approaches: passing the outer view controller as a delegate and passing the outer view controller's navigation controller as a property on the inner view controller.

Nothing seems to work. Is there a better solution?

Question:

1) Is wv being retained... when you call pushViewControllerFromSubview? I notice you have an autorelease deal here. Check the wv view within pushViewControllerFromSubview.

2) Another approach for replacing views is to use the '[self.view addSubView:myView];' and [myView removeFromSuperView];'... that may be a better approach than pushing the view controller.

Cheers

The root cause was that my "outer view" was actually a subview so I could not access its navigation controller directly. I had forgotten about that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM