Reputation: 6499
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?
Upvotes: 1
Views: 160
Reputation: 6499
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.
Upvotes: 0
Reputation: 61
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
Upvotes: 1