Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView when put in a UITableViewCell sometimes do not display the content

Tags:

cocoa-touch

I wonder if anyone else is facing the same issue. I have a UITextView field placed in a UITableViewCell. Sometimes it does not displays the text. When i click or scroll the table view, it appears. Any guesses?


Details:

I call a method in viewDidLoad method that calls a web service to retrieve some data. On receiving the data, i set the values of UILabel and UITextView. UILabel values appear fine, but the UITextView (sometimes) do not show the value until i move to subview or scroll up and down to revisit the area contaning UITextView. I'm showing UILabel and UITextView objects in UITableViewCell. I call [tableView reloadData] right after setting values in UILabel and UITextView, but i do not re-create the UITableViewCell.

Thanks for your reply and pointers.

like image 809
Mustafa Avatar asked Jan 19 '09 13:01

Mustafa


3 Answers

I solved this by calling [myTableView reloadData];

like image 178
Pavel Yakimenko Avatar answered Nov 19 '22 21:11

Pavel Yakimenko


I had this same problem more or less - a UITextView inside a custom UITableViewCell subclass would not display its text until you touched (and thus scrolled) the UITextView. This would only happen with the FIRST cell in the table. I couldn't figure out why it was happening, but the problem was easily fixed by just "nudging" the UITextView's contentOffset programmatically.

problemCell.textView.contentOffset = CGPointMake(0.0, 1.0);
problemCell.textView.contentOffset = CGPointMake(0.0, 0.0);
like image 24
danbretl Avatar answered Nov 19 '22 20:11

danbretl


This might have something to do with the fact that UITextView and UITableView are both subclasses of UIScrollView. So you have a scroll view inside of a scroll view, and it wouldn't surprise me if that was the cause of your problems.

If you don't need to edit the text within the table, just use a multi-line UILabel.

If you absolutely have to have a UITextView inside a UITableView, perhaps disabling scrolling on one of them might also fix the problem. (I think the property name is scrollEnabled or scrollingEnabled.)

like image 1
benzado Avatar answered Nov 19 '22 22:11

benzado