Application error while adding UITextview "[UITextView length]: unrecognized selector sent to instance"

I have a very strange problem with something that is probably easy to solve, but I can't get it to work. I want to add a UITextview to a UITableViewCell (but I also tried this in a simple view, this gives me the same problem). I do this in a storyboard or programmatically, the application crashes (sometimes only the second time the view is displayed!) With the message

- [UITextView length]: unrecognized selector sent to instance <...>

Here I add a UITextview (in CellForRowAtIndexPath: . @property UITextView *description , which I assigned to them, which was synthesized.

  //description cell if([indexPath section] == 2 && [indexPath row] == 0) { UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(7.0f, 5.0f, 285.0f, 140.0f)]; textView.editable = YES; textView.delegate = self; textView.backgroundColor = [UIColor clearColor]; textView.font = [UIFont systemFontOfSize:14.0f]; [cell.contentView addSubview:textView]; self.description = textView; } 

Please let me know if you need more code. Thanks in advance!

+4
source share
2 answers

A UITextView has no property length. If you try to enter the length of the text in a UITextView , use its property text to get an NSString , where you can use the text method. For instance.

 [[textView text] length]; 

But since I think you are most interested in the NSString UITextView form, just use

 [textView text] 
0
source

Invalid line self.description = textView; . Use self.description = textView.text; .

0
source

All Articles