首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >IOS FindObjectsInBackgroundWithBlock -> setNeedsDisplay

IOS FindObjectsInBackgroundWithBlock -> setNeedsDisplay
EN

Stack Overflow用户
提问于 2014-04-06 13:34:12
回答 1查看 231关注 0票数 1

我正在运行一个Parse程序,它获取数据并使用'findObjectsInBackgroundWithBlock‘从数据创建对象。一旦完成,我更新自己,然后调用'self.tableView setNeedsDisplay',但我的显示器上没有任何变化,也没有新的项目显示。我做错了什么吗?我该如何修复它呢?

代码语言:javascript
复制
-(void)pullDown{
NSLog(@"Began PullDown");
NSMutableArray *bugs = [NSMutableArray arrayWithObjects: nil];

//NSMutableArray *bugs = [NSMutableArray arrayWithObjects: nil];
NSLog(@"Journal POSTS");
PFQuery *queryJournal = [PFQuery queryWithClassName:@"Post"];
[queryJournal whereKey:@"user" equalTo:[PFUser currentUser]];
NSLog(@"WHEN ARE YOU CALLED?");
[queryJournal findObjectsInBackgroundWithBlock:^(NSArray *posts, NSError *error) {
    if (!error) {
        // The find succeeded.
        //NSLog(@"Successfully retrieved %@ Posts.", posts);
        // Do something with the found objects

        for (PFObject *object in posts) {
            int rating = object[@"Rating"];
            NSLog(@"RATING object: %@; int: %i", object[@"Rating"], rating);
            MSJournalerDoc *post = [[MSJournalerDoc alloc] initWithTitle:object[@"Title"] rating:rating thumbImage:object[@"imageFile"] fullImage:object[@"imageFile"]];
            [bugs addObject:post];
        }
        NSLog(@"HELL YA");
        NSLog(@"THE LIST: %@", bugs);
        self.bugs = bugs;
        NSLog(@"END OF LOOOOOOOOOOOOOOOPS %lu", bugs.count);
        [self.tableView setNeedsDisplay];
        NSLog(@"MOAR");
    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    } 
}];
}




- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    if ([PFUser currentUser]) {
        NSLog(@"CURRENT USER");
        [self pullDown];
        NSLog(@"POST CURRENT USER");
    }
    else{
        [self createUser];
        [self createBug];
    }


self.navigationItem.leftBarButtonItem = self.editButtonItem;

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;

//Change the Title
self.title = @"Posts";

self.navigationItem.leftBarButtonItem = self.editButtonItem;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
                                          initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                          target:self action:@selector(addTapped:)];

NSLog(@"Finished ViewDidLoad");
}
EN

回答 1

Stack Overflow用户

发布于 2014-04-06 15:33:27

你有几个不同的问题。

首先,在一个视图上调用setNeedsDisplay会导致它被重新绘制,但是这对于一个表视图来说是不够的,因为它的数据都没有更新。相反,您需要调用reloadData,它将自动更新数据并触发重绘。

其次,您正在尝试使用由parse返回的图像,但是parse从不返回图像(至少不是直接返回)。因此,访问object[@"imageFile"]将返回一个PFFile,而不是一个UIImage。您需要先调用getDataInBackgroundWithBlock:获取图片数据,然后才能使用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22890380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档