0

我在 UIScrollView 内放置了一个 UIView。有一种方法称为更新 UI,它基本上会更新 UI。但是,加载数据后,我需要向下滚动一点才能看到呈现的 UI。例如,我尝试的一件事是在 layoutSubviews 中隐藏 UITableView 并在 updateUI 中取消隐藏,但是我需要在 UIScrollView 上向下滚动一点,直到看到 UITableView。为什么会这样?这是我更新的 UI 代码:

当 UIScrollView 不滚动时,这个 updateUI 代码基本上会被触发。我有一个带有 UIScrollView 的 MyViewController,它实现了 UIScrollView 委托,基本上,当它不滚动时,它代表我的 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 回答