UITableView height update when loading a tweet

I have UITableViewCellone that contains TWTRTweetViewauto-layout. I upload a tweet, for example:

Limitations

Height Reduction Details

- (void)loadTweetWithId:(NSString *)tweetId {

    if (mTweetId == nil || ![mTweetId isEqualToString:tweetId]) {
        mTweetId = tweetId;
        [[[TWTRAPIClient alloc] init] loadTweetWithID:tweetId completion:^(TWTRTweet *tweet, NSError *error) {
            if (tweet) {
                NSLog(@"Tweet loaded!");
                [mTweetView configureWithTweet:tweet];
                [mTweetView setShowActionButtons:YES];
                //[mTweetView setDelegate:self];
                [mTweetView setPresenterViewController:self.viewController];
                [mTweetView setNeedsLayout];
                [mTweetView layoutIfNeeded];
                [mTweetView layoutSubviews];
                hc.constant = mTweetView.frame.size.height;
                [self updateConstraints];
                [self layoutIfNeeded];
                [self layoutSubviews];
                [self.tableView setNeedsLayout];
                [self.tableView layoutIfNeeded];
                [self.tableView layoutSubviews];
            } else {
                NSLog(@"Tweet load error: %@", [error localizedDescription]);
            }
        }];
    }
}

When a tweet-loaded cell doesn't resize, unless I scroll it and scroll it back. I tried several approaches, as you can see in the code snippet. But not from these works. My table view uses a full layout approach that does not implement cell height for a row function. How can i fix this?

UPDATE:

Using:

[self.tableView beginUpdates];
[self.tableView endUpdates];

impossible, because when I do this, all the cells are redrawn, and there is a very big jump, and this is unacceptable. I also confirmed that the tweet completion block works in the main thread.

Go video

UPDATE 2:

- id id. , /.

3:

xib . . , .

TwitterKit, TWTRTweetTableViewCell, . . , .

+6
3

,

- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths 
              withRowAnimation:(UITableViewRowAnimation)animation;
0

, , dispatch_async, , .

 dispatch_async(dispatch_get_main_queue(), ^{ 
      /*CODE HERE*/
 });

, :

- (void)loadTweetWithId:(NSString *)tweetId {

  if (mTweetId == nil || ![mTweetId isEqualToString:tweetId]) {
      mTweetId = tweetId;
    [[[TWTRAPIClient alloc] init] loadTweetWithID:tweetId completion:^(TWTRTweet *tweet, NSError *error) {

        dispatch_async(dispatch_get_main_queue(), ^{ 

        if (tweet) {
            NSLog(@"Tweet loaded!");
            [mTweetView configureWithTweet:tweet];
            [mTweetView setShowActionButtons:YES];
            //[mTweetView setDelegate:self];
            [mTweetView setPresenterViewController:self.viewController];
            [mTweetView setNeedsLayout];
            [mTweetView layoutIfNeeded];
            [mTweetView layoutSubviews];
            hc.constant = mTweetView.frame.size.height;
            [self updateConstraints];
            [self layoutIfNeeded];
            [self layoutSubviews];
            [self.tableView setNeedsLayout];
            [self.tableView layoutIfNeeded];
            [self.tableView layoutSubviews];
        } else {
            NSLog(@"Tweet load error: %@", [error localizedDescription]);
        }

    });

    }];
  }
 }
0

:

, (, , ) :

  • layoutSubviews . , . setNeedsLayout layoutIfNeeded .

  • updateConstraints. . , setNeedsUpdateContraints updateConstraintsIfNeeded. , , () ( ).

  • layoutIfNeeded , . , , mTweetView, , , ( ). layoutIfNeeded mTweetView superiew, ( , ):

    [contentView layoutIfNeeded];
    

, , , :

  • . , , . , ? , , , , , () , , , - , ( prepareForReuse).

, , , . ( .)


:

,

[self.tableView beginUpdates];
[self.tableView endUpdates];

, .

:

a UITableView (). , estimatedRowHeight .., , , . , , , .

, , .. . , - , "" , ( 1000). : !

() - , . , () API -

- (void)beginUpdates;
- (void)endUpdates;

, :

?

, . , , , !

You probably won't (and shouldn't) resize all visible cells all the time. (That would be pretty confusing for the user ...)

0
source

All Articles