2012-06-17 101 views
0

我有一個UIView在UIScrollView內部佈局。有一種稱爲更新UI的方法,它基本上更新了UI。然而,在數據加載後,我需要向下滾動一下以查看呈現的UI。 例如,我試過的一件事是在layoutSubviews中隱藏UITableView,並在updateUI中取消隱藏,但是我需要向下滾動一下UIScrollView,直到看到UITableView。這是爲什麼發生?這裏是我更新的UI代碼:UIView在UIScrollVIew不更新視圖

這個updateUI代碼基本上是在UIScrollView沒有滾動時觸發的。我有一個帶有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"); 
    } 
} 
+0

聽起來好像你是從'UIScrollViewDelegate'方法調用'updateUIView' - 如果這是真的,哪一個? – Barjavel

回答

0

嘗試調用...

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

在你的函數的末尾,而不是在一開始。希望有所幫助!