views:

1027

answers:

1

I have a custom UITableViewCell with a UIScrollView in it that is wired to the cell controller. When I assign text to the scrollview, some cells get the correct text, some are blank, some redisplay old text and others have the scrollview clipped around the 2nd or 3rd line of text. It seems random on what will happen. I followed the suggestion here of using a timer to fix blank cells, http://www.bdunagan.com/2008/12/08/uitextview-in-a-uitableview-on-the-iphone/, but that didn't help. I placed the timer code in the cellForRowAtIndexPath method.

I've also tried calling

[cell.textview setNeedsDisplay];

after text is assigned to the textview but it doesn't have any affect.

When I use a textfield or label, everything looks fine. However, I need something that can scroll text. Any suggestions on a fix or better way?

+1  A: 

Update: Found this on the dev forums (specifically mentions your problem):

https://devforums.apple.com/message/38944#38944

I would follow the link it has some more detailed info.

 // view controller

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
     NSArray*     visibleCells = [self.tableView visibleCells];

     for (UITableViewCell* cell in visibleCells)
     {
          if ([cell.reuseIdentifier isEqualToString:kTextViewCellID])
          {
               [(MTextViewCell*)cell refresh];
          }
     }
}

// MTextViewCell 


- (void)refresh
{
     // mucking with the contentOffset causes the textView to redraw itself
     CGPoint     contentOffset = mTextView.contentOffset;
     CGPoint     contentOffset1 = { contentOffset.x, contentOffset.y + 1.0f };

     mTextView.contentOffset = contentOffset1;
     mTextView.contentOffset = contentOffset;
}


Try calling:

[tableView reloadData];

After you update all the textViews.

Corey Floyd
textViews are updated in cellForRowAtIndexPath. I tried calling [tableView reloadData]; there but it had no affect.
4thSpace
Right before return cell; I do NSLog(@"\nrow=%d textview.text: %@",row, cell.textview.text); and it always has the correct value. But hardly ever displays it. Usually the cells are blank.
4thSpace
if you scroll the table, do the values get updated as you scroll?
Corey Floyd
No. It is random. Most are blank, some are repeats, some appear to be correct (by order). This is very similar to the problem I'm experiencing: http://discussions.apple.com/thread.jspa?messageID=8203919.
4thSpace
found something on the dev forums
Corey Floyd
Excellent! That works. From the forum post, seems as though 3.0 has a fix for this.
4thSpace