Reputation: 10264
This works on the iPhone BTW (Both running iOS 5.1)
My app freezes when I call [self dismissModalViewControllerAnimated:NO];
I have tried many different approaches:
My code how I have it now:
-(void) doneEditing:(NSString *)value
{
[multiLineText dismissModalViewControllerAnimated:NO];
self.currentActiveTextView.text = value;
self.currentActiveTextView = nil;
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
multiLineText = [[MultilineTextViewController alloc] init];
multiLineText.delegate = self;
multiLineText.text = textView.text;
self.currentActiveTextView = textView;
[self presentModalViewController:multiLineText animated:NO];
}
MultilineTextViewController.h
@protocol DoneEditing
-(void)doneEditing:(NSString*)value;
@end
@interface MultilineTextViewController : UIViewController
{
UITextView *inputText;
id<DoneEditing> delegate;
}
@property (nonatomic, strong) NSString *text;
@property (nonatomic, strong) id<DoneEditing> delegate;
@end
Function called from a done button
-(void) done:(id)sender
{
[delegate doneEditing:inputText.text];
}
I have tried dismissing the modal in my done function
I have tried it in both places with self
I have also tried this in MultilineTextViewController
if ([[self parentViewController] respondsToSelector:@selector(dismissModalViewControllerAnimated:)]){
[[self parentViewController] dismissModalViewControllerAnimated:NO];
} else {
[[self presentingViewController] dismissViewControllerAnimated:NO completion:nil];
}
Just some history, when a user clicks a UITextView
I use to open a new ModalViewController
to allow the user more space to type large amounts of text, after completion the user presses done and I call the delegate method to put the text on the original form.
If I change animated to yes in any of the above given cases it still doesn't work but instead of freezing I get the NSInternalInconsistencyException
Attempting to begin a modal transition from <WorkflowViewController: 0xc6846b0> to <MultilineTextViewController: 0xc64b960> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed
Any ideas?
I can't seem to find a reason for this thing not to work...
Upvotes: 3
Views: 1622
Reputation: 5393
Try checking how many times doneEditing is being called e.g. with an NSLog in there.
Edit:
Try adding delay before dismissing the modalViewController:
[self performSelector:@selector(dismiss) withObject:nil afterDelay:1.0];
- (void)dismiss {
[self dismissModalViewControllerAnimated:NO];
}
Upvotes: 0
Reputation: 131426
In recent versions of iOS, you can send the dismissModalViewControllerAnimated: message to the modal itself.
Apple juggled the way this works recently. Try sending to the modal itself.
Upvotes: 0
Reputation: 16932
I don't understand your line
[multiLineText dismissModalViewControllerAnimated:NO];
since multiLineText it your modal view controller, the dismiss has to be called by the view controller presenting it, i.e., in your first example (since you have set delegate to the presenting view controller)
[multiLineText.delegate dismissModalViewControllerAnimated:NO];
should work. You set delegate to nil to avoid dismissing twice.
Upvotes: 0
Reputation: 2579
Ensure that your text view properly resigns its first responder status prior to dismissing it from the screen.
Something like:
[inputText resignFirstResponder];
Upvotes: 0
Reputation: 830
Since its iPad maybe you can use a UIPopOverController when you want to present the view. Try creating a UIPopOverController initiating it with the view controller for your modal view. You can set the size and where it will popover from. You can set the class it is called from to be the delegate for the view so that you can get notifications.
Hope this helps
Upvotes: 2