views:

289

answers:

1

I've got an imagePickerController which allows the user to take or select an image. In - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info; I would like to trigger opening another modal view to capture the caption. I have a call for that purpose...

-(void) getcaption:(id) obj {
    textInput * ti = [[textInput alloc] initWithContent:@"" header:@"Caption for photo" source:2];
    ti.delegate = self;
    [self presentModalViewController:ti animated:YES];
    [ti release];
}

The question is how to call getcaption without triggering a spiral of

#6663 0x324abb18 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] ()

At the moment I do

[self performSelector:@selector(getcaption:)  withObject:nil afterDelay:(NSTimeInterval)1];

in didFinishPickingMediaWithInfo which is nasty, and only 95% reliable

+2  A: 

I assume the problem is that you are attempting to show your new view before your old view has closed? I assume you are in a parent view controller that is displaying both modal views with it being the parent. If that is the case, the point at which you should display the new modal view is when the parent view has completely finished hiding the previous modal view. Specifically, this happens at

- (void) viewDidAppear:(BOOL)animated

You'll want to make sure that you only show the second modal view after the previous one has finished, of course (that is, don't show it when the parent view is appearing for any other reason)

Ed Marty
Thanks Ed. I'd thought that might be the case, I'd wanted to avoid that as I am not sure how to architect that trigger. My brute force method there would be to have a property in the viewcontroller:i.e. get didFinishPickingMediaWithInfo to set a property such as bool viewWillAppearShouldRequestCaption and use that in viewWillAppear to trigger the display. Is there a better architecture to request that sort of thing ?
Andiih
Any better architecture would be more complicated than that, and what you've suggested is what I would have gone with.
Ed Marty
This kind of worked. I still needed to use the performSelector:withObject:AfterDelay: from viewDidAppear: otherwise if I call it directly I get an EXEC BAD ACCESS just as the views all appear. I'm not happy I've gotten to the bottom of this.(Also I said ViewWillAppear in my first comment - I did mean ViewDidAppear)
Andiih
It might be that it just needs to be scheduled on the next iteration of the run loop. Even a delay of 0 might be sufficient, if that is the case.
Ed Marty
Trying a delay of 0 now...
Andiih
Yep. That works. Thanks
Andiih