Hello,
My code started to behave at least strange. I have a view controller NewPostUIViewController, from within which I display modally SettingsUIViewController which contains a table view. In the cell of the table view I have text fields. For each of the text fields I have text fields delegates.
In the - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
method of the delegates I have the following code:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
UITableView *tmpTableView = [viewController valueForKey:@"settingsTableView"];
static const NSUInteger navBarHeight = 44;
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
tmpTableView.frame = CGRectMake(0, navBarHeight, appFrame.size.width, appFrame.size.height-navBarHeight-216); //216 for the keyboard going up
NSIndexPath *indPath = [NSIndexPath indexPathForRow:2 inSection:3];
[tmpTableView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
[UIView commitAnimations];
return YES;
}
There is also:
- (void)textFieldDidEndEditing:(UITextField *)textField {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
UITableView *tmpTableView = [viewController valueForKey:@"settingsTableView"];
static const NSUInteger navBarHeight = 44;
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
tmpTableView.frame = CGRectMake(0, navBarHeight, appFrame.size.width, appFrame.size.height-navBarHeight);
[UIView commitAnimations];
}
The scenario looks like this:
1. In the NewPostUIViewController I modally display SettingsUIViewController,
2. Choose one of the text fields in one of the cells, the keyboard is displayed (but I don't use it) and I click the button which dismiss the modal view, so I'm back in NewPostUIViewController
3. In the NewPostUIViewController I again modally display SettingsUIViewController
4. The table view appears just like in step #2, I click on the same text field and - CRASH with *** -[SettingsFieldsUITextViewDelegate respondsToSelector:]: message sent to deallocated instance 0xc17e8ff0
I started debugging and got to the point that dealloc in the SettingsUIViewController is called (and in this dealloc I release SettingsFieldsUITextViewDelegate) just before the crash.
This strange behaviour appeared after I added the code above, so I guess that there could be something wrong, but I just cannot see it.
Any ideas why this dealloc is called?