Shnaps wrote:
... when , I marked the text for the UITextView as not editable in app's NIB, the *BeginEditing methods were not called
Ookay.. I unchecked Editable in the IB Text View Attributes panel and added a button to toggle the text view's editable property ON or OFF. Here's the controller implementation for reference:
// SamViewController.m
#import "SamViewController.h"
@implementation SamViewController
@synthesize theTextView;
@synthesize buEdit;
- (void)setEditTitle {
if ([theTextView isEditable])
[buEdit setTitle:@"Edit Off" forState:UIControlStateNormal];
else
[buEdit setTitle:@"Edit On" forState:UIControlStateNormal];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setEditTitle];
}
- (IBAction)edit {
if ([theTextView isEditable]) {
[theTextView resignFirstResponder];
theTextView.editable = NO;
}
else
theTextView.editable = YES;
[self setEditTitle];
}
- (IBAction)done {
[theTextView resignFirstResponder];
}
- (void)dealloc {
[buEdit release];
[theTextView release];
[super dealloc];
}
#pragma mark -
#pragma mark Text View Delegate Methods
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
NSLog(@"textViewShouldBeginEditing");
return YES;
}
- (void)textViewDidBeginEditing:(UITextView *)textView {
NSLog(@"textViewDidBeginEditing");
}
- (void)textViewDidChange:(UITextView *)textView {
NSLog(@"textViewDidChange");
}
- (void)textViewDidChangeSelection:(UITextView *)textView {
NSLog(@"textViewDidChangeSelection");
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
NSLog(@"textViewShouldEndEditing");
return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView {
NSLog(@"textViewDidEndEditing");
}
@end
I got results similar to your post, but on this system, those results are easily explained. I found that turning the editable property on always gave first responder status to the text view. I.e. programmatically changing theTextView.editable from NO to YES immediately brings up the keyboard and activates the caret. In this case there are no ShouldBegin or DidBeginEditing messages, and we shouldn't expect any because editing was started programmatically (i.e. the delegate is only there to customize the response to user actions). Of course after touching the "Edit On" button, a subsequent touch on the text view doesn't cause the delegate to get any BeginEditing messages, because editing has already started.
So over here, there's no indication that unchecking Editable in IB did anything unusual. In any case, if that box isn't checked, there's no way to begin editing without first setting the property programmatically.
Were you able to set the editable property to YES in code without activating the keyboard and caret? If so, I don't think I'll be able to reproduce your result. When you did your tests, is it possible you didn't consider that the keyboard and caret were already active when you expected a touch on the text view to produce BeginEditing messages?
- Ray
p.s.: You can ignore the #pragma lines. A pragma is a directive to the build system which has no effect on the source code. Sometimes a pragma is used to modify the compiler options for a certain block of code, often to turn off a particular warning. In the above example, the pragma lines are just formatting the list of methods that Xcode displays when you expand the
Function Menu in the center of the Navigation Bar in an Editor window. - R