我正在运行一个Parse程序,该程序使用'findObjectsInBackgroundWithBlock'抓取数据并从中创建对象。一旦完成,我更新自我,然后调用'[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");
}
答案 0 :(得分:1)
你有几个不同的问题。
首先,在视图上调用setNeedsDisplay
会导致重绘,但这对于表视图来说还不够,因为它的数据都没有更新。相反,您需要调用reloadData
来更新数据并自动触发重绘。
其次,您正在尝试使用parse返回的图像,但解析永远不会返回图像(至少不会直接返回)。因此,访问object[@"imageFile"]
会返回PFFile
,而不是UIImage
。您需要先致电getDataInBackgroundWithBlock:
以获取图像数据,然后才能使用它。