Object msg send error coming
I am trying to do the following
- (void)textViewDidChange:(UITextView *)textView{
if(textView == txtYourTip){
if([txtYourTip.text length] < 100){
strTip = txtYourTip.text;
NSLog(@"%@",strTip);
} else {
NSLog(@"%@",strTip);
txtYourTip.text = strTip;
}}
Application crashes when controls goes to else part. strTip is of type NSString.
viewDidLoad contains
txtYourTip = [[UITextView alloc] initWithFrame:CGRectMake(15, 80, 290, 80)];
[txtYourTip.layer setBorderColor:[[UIColor lightGrayColor] CGColor]];
[txtYourTip setDelegate:self];
[txtYourTip setContentInset:UIEdgeInsetsMake(10, 10, 10, 10)];
txtYourTip.layer.cornerRadius = 10.0;
[txtYourTip.layer setBorderWidth:2.0];
[contentView addSubview:txtYourTip];
strTip = [[NSMutableString alloc] i开发者_如何学Pythonnit];
If you put the strTip = @"" in viewDidLoad like you said I think that is the reason. Allocating a NSString with @"a text" is making it autoreleased. So at some point the data is released but the pointers points to it. When you try to display it you have an exception.
Try this in your viewDidLoad :
strTip = [[NSString alloc] init];
or
strTip = @"";
[strTip retain];
Either one should work and will need a :
[strTip release];
strTip = nil;
in the view viewDidUnload so you don't leak
精彩评论