0

UIScrollView 内にレイアウトされた UIView があります。基本的にUIを更新する update UI というメソッドがあります。ただし、データが読み込まれた後、レンダリングされた UI を確認するには、少し下にスクロールする必要があります。たとえば、私が試したことの 1 つは、layoutSubviews で UITableView を非表示にし、updateUI で再表示することですが、UITableView が表示されるまで UIScrollView を少し下にスクロールする必要があります。なぜこうなった?更新された UI コードは次のとおりです。

この updateUI コードは基本的に、UIScrollView がスクロールしていないときに発生します。UIScrollViewデリゲートを実装するUIScrollViewを含むMyViewControllerがあり、基本的にスクロールしていないときはUIViewにデリゲートして、ビューを今すぐ更新できることを伝えます。

- (void) updateUI
{
    self.isScrolling = NO;

    NSLog(@"UPDATE UI");

    AHMyImageData *object = self.object;

    if ([object isNotNull]){

    [self.tableView_ reloadData];

    if (![self.userProfileImage_.image isNotNull]){
        [self.userProfileImage_ setImageWithURL:[NSURL URLWithString:object.profilePicture_] andAnimate:YES];
    }

    if (![self.imageView_.image isNotNull]){
        NSString *url = [[object.image_ valueForKey:@"low_resolution"] valueForKey:@"url"];
        [self.imageView_ setImageWithURL:[NSURL URLWithString:url] andAnimate:YES];
    }

    if (object.userHasLiked){
        [self.likeButton_ setImage:[UIImage imageNamed:@"btn-like-down.png"] forState:UIControlStateNormal];
    } else {
        [self.likeButton_ setImage:[UIImage imageNamed:@"btn-like.png"] forState:UIControlStateNormal];
    }

    if ([object.text_ isNotNull]){
        NSMutableAttributedString * attributedString = [NSMutableAttributedString attributedStringWithString:object.text_];
        [attributedString setFont:[UIFont fontWithName:@"HelveticaNeue" size:15]];
        [self.titleLabel_ setAttributedText:attributedString];
        [self parseTagsInComment:object.text_];
    }

    NSMutableAttributedString * usernameAttributedString = [NSMutableAttributedString attributedStringWithString:object.username_];
    [usernameAttributedString setFont:[UIFont fontWithName:@"HelveticaNeue" size:14]];
    [usernameAttributedString setTextColor:[UIColor colorWithRed:86.0/255.0 green:134.0/255.0 blue:172.0/255.0 alpha:1.0] range:NSMakeRange(0, [object.username_ length])];
    [usernameAttributedString setTextBold:YES range:NSMakeRange(0, [object.username_ length])];

    [self.usernameLabel_ setAttributedText:usernameAttributedString];

    NSString * imageCreatorUsernameURL = [NSString stringWithFormat:@"userid://%@", object.userId_];
    [self.usernameLabel_ addCustomLink:[NSURL URLWithString:imageCreatorUsernameURL] inRange:NSMakeRange(0, [object.username_ length])];
    [self.usernameLabel_ setUnderlineLinks:NO];
    [self.usernameLabel_ setDelegate:self];

    [self.likesCountLabel_ setText:[NSString stringWithFormat:@"%d", object.likesCount]];
    [self.commentsCountLabel_ setText:[NSString stringWithFormat:@"%d", object.commentsCount]];

    if ([object.createdTime_ isNotNull]){
        [self.imageTimePostedLabel_ setText:[NSString timestampToString:object.createdTime_]];
    }


    [self setNeedsDisplay];
    [self setNeedsLayout];

    } else {
        NSLog(@"OBJECT IS NULL");
    }
}
4

1 に答える 1

0

電話してみる...

[self.tableView_ reloadData];
// I think you need to call reloadData only
// AFTER you do all your fun updating stuff
[self setNeedsDisplay];
[self setNeedsLayout];

機能の最初ではなく、関数の最後に。それが役立つことを願っています!

于 2012-06-17T19:12:23.017 に答える