Reputation: 111
I have a App that uses the In App feature.
-(void) completeTransaction: (skPaymenttransaction *)transaction{
}
When the above method gets called i want to remove all subviews and go back to my main menu window (the first view in my App).
Can anyone suggest to cleanest and best way to do this?
Cheers
EDIT:
Just to make things clear
Im not sure if this makes a difference but i have my main menu screen, then iam doing the following with an enter button.
UIViewController *controller = [[UIViewController alloc] initWithNibName:@"NibFile" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
Then i have a main screen with a button then when a user taps it, it then presents them with another modal view controller as above. On this view is a button that says BUY on it. They use clicks this and then the StoreKit does it business and once the payment is complete i want to get rid of the two modal controllers above and be left with the main menu screen.
Any Ideas.. ive tried as above
EDIT 2:
@Jordan Thanks,
But not sure if im doing this correctly. I understand the above code.
But when i start my app my app delegate loads a viewcontroller which is my main menu. Then i have a button that takes me to another view and on there is my features if the user clicks a feature that is not unlocked then it displays another view controller with the store on.
So with this in mind how do i get back to my main menu.
I have tried the following:
NSArray *subviews = [myAppdelegate.viewcontroller.view subviews];
for (int i=0; i<[subviews count]; i++)
{
[[subviews objectAtIndex:i] removeFromSuperview];
}
but i get and error along the lines of:
expected ':' before '.' ?
Upvotes: 0
Views: 2987
Reputation: 32270
We have to get the views to be removed in an array so that we can remove everything by means of enumeration
NSArray *ChildViews = [ParentView subviews];
for (UIView *childView in ChildViews) {
[childView removeFromSuperview];
}
Upvotes: 0
Reputation: 21760
If you're talking about UIViewControllers and not subViews (they are different),then you can use:
[self.navigationController popToRootViewControllerAnimated:YES];
You're either adding UIViews to a UIViewController, in which case use my code above, or You're pushingViews (e.g. pushViewController) on top of a UIViewController, in which case use the code here.
Upvotes: 0
Reputation: 21760
This should work.
// view is equal to your main view
NSArray *subviews = [view subviews];
for (int i=0; i<[subviews count]; i++)
{
[[subviews objectAtIndex:i] removeFromSuperview];
}
Upvotes: 1