Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had difficulty getting this to work too, not much info around on this but I finally got it working. When you make your <code>DTAttributedTextCell</code> set the delegate of it's <code>DTAttributedTextContentView</code> property to your tableviewcontroller</p> <p><code>cell.attributedTextContextView.delegate = self;</code></p> <p>and implement this method:</p> <pre><code>- (UIView *)attributedTextContentView:(DTAttributedTextContentView *)attributedTextContentView viewForAttachment:(DTTextAttachment *)attachment frame: (CGRect)frame{ if([attachment isKindOfClass:[DTImageTextAttachment class]]){ FVLazyImageView *imageView = [[FVLazyImageView alloc] initWithFrame:frame]; imageView.contextView = attributedTextContentView; imageView.delegate = self; // url for deferred loading imageView.url = attachment.contentURL; return imageView; } return nil; } </code></pre> <p>From inside this method create your <code>DTLazyImageView</code> and set its delegate. I made a subclass of <code>DTLazyImageView</code> to hold an extra property, a reference to the <code>DTAttributedTextContentView</code> of that individual cell, to be used when the <code>DTLazyImageViewDelegate</code> is called.</p> <p>Then when <code>- (void)lazyImageView:(DTLazyImageView *)lazyImageView didChangeImageSize:(CGSize)size</code> is called take the <code>lazyImageView</code> variable that was passed and cast it to your subclass to get the <code>DTAttributedTextContentView</code> you stored. Use the same method that comes in the example but just replace the <code>_textView.attributedTextContentView</code> with the <code>DTAttributedTextContentView</code> you carried over.</p> <p>Also be sure to make the cells the way he does in the DemoSnippetsViewController, if you're loading images you will need to have variable height cells and you must implement <code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath</code></p> <h3>Update for Stricklands question</h3> <p>I haven't touched my code in about a year so I'm not so sure about this. But here is what I think is happening. I never call <code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath</code>, I just implement it and it is called when the cell is reloaded. When is it reloaded? From what i gather, I implement the delegate for the lazy image view <code>- (void)lazyImageView:(DTLazyImageView *)lazyImageView didChangeImageSize:(CGSize)size;</code> So after the image is downloaded from the web, in that call I check if the image size has changed and call <code>[DTAttributedTextContentView relayoutText]</code> , which I think kicks off the reloading.</p> <p>Here's my heightForRowAtIndexPath implementation:</p> <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ DTAttributedTextCell *cell = (DTAttributedTextCell *)[self tableView:tableView preparedCellForIndexPath:indexPath]; if([indexPath isEqual:self.selectedIndex]){ return MAX([cell requiredRowHeightInTableView:tableView] + 40,120); } return MAX([cell requiredRowHeightInTableView:tableView], 80); } </code></pre> <p>Once the download is complete and the refresh is called it calls the <code>[DTAttributedTextCell requiredRowHeightInTableView:]</code> to pass along the new size with a small buffer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload