I use a UITextView in a subclass of UIViewController which I've named FacebookPostViewController. So the purpose of the text view is to allow the user to review the content of a prepared post, possibly make changes to it, and then decide if the text from the text view should be posted to Facebook, or not.
I've set the returnKeyType property of the UITextView to UIReturnKeySend, because I want to use it to actually post to Facebook. Canceling is possible via a back button in the NavBar.
So the FacebookPostViewController is delegate of the UITextView, and in the textView:shouldChangeTextInRange:replacementText: delegate method, I check for a newline insertion, and then call my sendTextToFacebook method:
- (void)sendTextToFacebook;
{
// prepare sending
NSMutableDictionary* sendParameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:self.textView.text, @"message", nil];
// request sending to own feed
[[FacebookController sharedFacebookController].facebook requestWithGraphPath:@"me/feed" andParams:sendParameters andHttpMethod:@"POST" andDelegate:self];
}
As you can see, I specify self as the FBRequestDelegate, so I also implement
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error;
- (void)request:(FBRequest *)request didLoad:(id)result;
where I give the user feedback if posting was successfull or not.
However, I've figured that it takes some time until the Facebook server replies, so I want to have the complete UI inactive until one of the two delegate methods is called. Therefore, I've implemented the following method:
- (void)disableUserInterface;
{
self.textView.editable = NO;
self.loginButton.enabled = NO;
self.logoutButton.enabled = NO;
[self.navigationItem setHidesBackButton:YES animated:YES];
[self.spinner startAnimating];
self.spinner.hidden = NO;
}
My problem is that calling self.textView.editable = NO will hide the keyboard, which looks stupid. If I remove that line, the keyboard won't disappear, but the user can change the textView content while the text is sent to Facebook. However, as posting is already initiated. these changes won't actually appear in Facebook.
I thought I could simply implement another UITextViewDelegate method:
- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
return NO;
}
The UI result is then exactly how I'd like to have it. However, this will lead to a EXC_BAD_ACCESS crash later when I've popped the FacebookPostViewController and then push another view to the UINavigationController. Ther error then is
*** -[UITextView isKindOfClass:]: message sent to deallocated instance 0x20c650
So, has anybody an idea how I can solve my problem to make the UITextView uneditable, but prevent the keyboard from disappearing?!?