I have a UITableViewController that when a cell is pressed, I want the controller to pop itself, and then have the controller it pop’s to, push another view controller onto the stack.
I am invoking this method because the popped-to viewController is the delegate of the tableViewController
I am currently invoking this method with a delay on it, because otherwise, everything gets screwed up waiting for the animation to end. Doing it this way seems a bit hacky and seems to me like it would fail if someone’s device didn’t pop the view in the allotted wait time I have given it.
Here is some of the code:
//**** code in my tableViewController ***//
[self.navigationController popViewControllerAnimated:YES];
[self.delegate cellPressedInTableViewControllerWithCalculationsModel:(id)anArgmentMyDelegateMethodTakes];
// **** Code in the viewController being popped to ****//
//CalculationsViewController is a subclass of UIViewController
CalculationsViewController *calcViewController = [[CalculationsViewController alloc] init];
//some customization code would go her
[self.navigationController performSelector:@selector(pushViewController:animated:) withObject:calcViewController afterDelay:0.75];
//this seems like the arbitrary part, the 0.75 second delay.
[calcViewController release];
There seems like there should be a better way to pop/push through delegation that will execute after the animation finishes. The wait time seems to me like it could cause unexpected problems.
I have also tried using:
performSelectorOnMainThread:withObject:waitUntilDone
But the code just executes immediately and the view hierarchy screwed up.
I have also looked at this question:
Delegation question
and it has gotten me this far, but I am curious to see if there is a better way to perform such a task,
Thanks.
edit: I have also tried wrapping the method in an instance of NSInvocation, and I couldn’t get it to coordinate the method call until after the animation finished without arbitrarily setting the delay
You should use a flag to overcome this situation. You set this flag in viewWillDisappear method of view controller being popped. When this flag is set then and then you can push another view controller on stack. Hope it’s clear.