1

I found great piece of code under the link here. But in my case there is more to do.
My main VC is a UITableViewController. Controller can display two type of cells. One of them (MyCell) is having a subview of type UITextView (textView). The size of it's text is based on fontSize variable. I have two buttons that can lower or greater the fontSize, then both reloads the tableView. According to the link above and having in mind that UITextView is a subclass of UIScrollView, I made my piece of code I placed in didEndDisplayingCell:

-(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (cell.class == [ConduiteTableCellView class])
    {
        ConduiteTableCellView *conduiteCell = (ConduiteTableCellView *)cell;
        for (UIView *view in conduiteCell.textView.subviews)
        {
            if ([view isKindOfClass:[UIImageView class]])
            {
                if (view.alpha == 0 && view.frame.size.width < 10)
                {
                    view.alpha = 1;
                    break;
                }
            }
        }
        [conduiteCell.textView flashScrollIndicators];
    }
}

But after the [self.tableView reloadData]; nothing happens. What am I doing wrong? Shall I place my code in some other method?

mcgtrt
  • 657
  • 6
  • 22

1 Answers1

1

Remove [conduiteCell.textView flashScrollIndicators]; and it will work.

-(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
  if (cell.class == [ConduiteTableCellView class])
  {
    ConduiteTableCellView *conduiteCell = (ConduiteTableCellView *)cell;
    for (UIView *view in conduiteCell.textView.subviews)
    {
      if ([view isKindOfClass:[UIImageView class]])
      {
        if (view.alpha == 0 && view.frame.size.width < 10)
        {
          view.alpha = 1;
          break;
        }
      }
    }
  }
}
trungduc
  • 11,926
  • 4
  • 31
  • 55
  • Sorry, but this doesn't work. I guess I have messed up searching for scroll bar inside my `textView` or I placed it in wrong method, elsewhere I don't know what's happening :v – mcgtrt Dec 08 '17 at 11:54
  • I have created a project and tried your code. it works if i remove that line. – trungduc Dec 08 '17 at 12:02
  • And what if you scroll down or up. Does it stay visible? – mcgtrt Dec 08 '17 at 12:12
  • If i scroll tableView up or down, it’s still visible – trungduc Dec 09 '17 at 05:51
  • It’s not about the tableView, it’s about scrolling the textView. TableView has scrollable content disabled. If text is bigger than textView frame, then scroll bar should be shown and textView should be scrollable – mcgtrt Dec 09 '17 at 08:14
  • I tried add observer for `alpha` and `layer.opacity` keyPath and change them to 1 if they are changed but scrollbar was still invisible when i scroll. Seem like we don't have any way to keep it stay visible when scrolling. – trungduc Dec 10 '17 at 12:30
  • So I guess there is only a DIY scroll bar left for me. Thanks a lot! – mcgtrt Dec 10 '17 at 20:36