UIView in UIScrollVIew not updating views

I have a UIView layed out inside a UIScrollView. There is a method called update UI which basically updates the UI. However after the data is loaded I need to scroll down a bit to see the UI rendered. For example, one thing I tried is to hide the UITableView in layoutSubviews and unhide it in updateUI, however I need to scroll down a bit on my UIScrollView until I see the UITableView. Why is this happening? here's my updated UI code:

This updateUI code is basically fired off when the UIScrollView is not scrolling. I have a MyViewController with a UIScrollView in it that implements UIScrollView delegate, and basically when it's not scrolling it delegates back to my UIView telling that you can update the view now.

- (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");
    }
}

Answers


Try calling...

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

At the very end of your function, not at the very start. Hope that helps!


Need Your Help

What is the editor used for writing RFC text files?

editor rfc

I am just wondering how much effort is required to write a text file like that with page numbers, table of contents, headers, footers etc. Is there any editor or some thing like TeX that is used for

How to display spin.js before executing some function?

javascript jquery callback web-worker spin.js

I want to display a spinner before some complicated function, i.e. dummyCounter(). The code looks like: