我正在运行一个Parse程序,该程序将获取数据并使用'findObjectsInBackgroundWithBlock'从中创建对象。完成此操作后,我将更新self,然后调用“[self.tableView setNeedsDisplay]”,但显示内容没有任何变化,也没有显示新项目。难道我做错了什么?以及如何解决?

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

最佳答案

您有几个不同的问题。

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

其次,您尝试使用解析返回的图像,但是解析永远不会返回图像(至少不是直接返回)。因此,访问object[@"imageFile"]将返回PFFile而不是UIImage。您需要先调用getDataInBackgroundWithBlock:来获取图像数据,然后才能使用它。

关于ios - iOS的FindObjectsInBackgroundWithBlock-> setNeedsDisplay,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22890380/

10-10 15:02