0

I've spent hours and I cant figure this out. I have a detail view controller (UITableView) which is launched here:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    EventLocationDetailController *newDetailViewController = [[EventLocationDetailController alloc] initWithNibName:@"EventLocationDetailController" bundle:nil];
    self.eventDetailController = newDetailViewController;
    [self.navigationController pushViewController:self.eventDetailController animated:YES];

    [newDetailViewController release];

}

In the detail view controller there is a button method which calls the below method to display a slide-in-slide-out animation confirming the users choice:

-(void)confirmLastActionWithMessage:(NSString *)message {

ConfirmActionViewController  *newConfirmActionViewController = [[ConfirmActionViewController alloc] initWithNibName:@"ConfirmActionViewController" bundle:nil];
self.confirmActionViewController = newConfirmActionViewController; 
[newConfirmActionViewController release];

[[self.view superview] addSubview:self.confirmActionViewController.view];

}

Protocol method called by the ConfirmActionViewController indicating that the animation is finished.

-(void)didFinishConfirmDisplay:(UIView *)viewToRemoveFromSuperview {

     [viewToRemoveFromSuperview removeFromSuperview];
}

This works perfect the first time I press the button. If I pop the detail controller and push it back on to the stack and press the button again, nothing happens and the detail controller's superview is nil every time I invoke the method after that. Superview is not nil in the viewWillAppear method for the detail view, only when It gets to the confirmLastActionWithMessage method. No other user interaction happens in between. How do I get the superview back? I have a similar code that works without animation.

I've also noticed that the detail view controller hasn't called dealloc when popped off the stack. Not sure where the problem is.

Thanks.

EDIT 1

OK. I replaced the addSubview line with this one:

[self.view insertSubview:self.confirmActionViewController.view atIndex:0];

and the animation view appeared underneath one of the table cells. Could one of the table cells steal the superview?

b.dot
  • 109
  • 1
  • 11
  • What do your properties look like? Specifically, have you added custom logic in the properties? – N_A Jul 03 '12 at 16:52
  • @property (nonatomic, retain) ConfirmActionViewController *confirmActionViewController; – b.dot Jul 03 '12 at 17:59
  • The implementation, not the declaration. Do you have an `@synthesize` or something else? – N_A Jul 03 '12 at 18:00
  • Yes I have @synthesize confirmActionViewController; – b.dot Jul 03 '12 at 18:06
  • I think you had it right the first time. You don't want to add views to your UITableView (assuming the view to which you're adding it is a UITableView). – N_A Jul 03 '12 at 18:08

1 Answers1

1

Well I don't really understand why you should add the subview to the superview. Why not add it just to self.view

I may not be able to explain why there is no superview but try either adding the controller view to self.view or

[[[[UIApplication sharedApplication] delegate] window] addSubview:yourview];

This will render the view on top of everything.

atastrophic
  • 3,153
  • 3
  • 31
  • 50
  • I tried that, but I had to adjust the starting point for the animation due to the toolbar at the bottom of the view. The animation will appear in other views - with and without toolbars. I was hoping the code could be portable and the animation could be launched without calculating where the bottom of the screen was for each use. Looks like that may be the only option if I don't get another answer. Thanks. – b.dot Jul 03 '12 at 17:20
  • Create a new enum with Possible cases for which you have to calculate the starting point for animation like with toolbar, without toolbar, with navigation bar etc. then modify you method `-(void)confirmLastActionWithMessage:(NSString *)message` to take an extra parameter of that enum type and calculate starting point within a switch block. When calling the method pass on the argument as required. This will render your code more portable. – atastrophic Jul 05 '12 at 04:27