我正在运行一个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");
}发布于 2014-04-06 15:33:27
你有几个不同的问题。
首先,在一个视图上调用setNeedsDisplay会导致它被重新绘制,但是这对于一个表视图来说是不够的,因为它的数据都没有更新。相反,您需要调用reloadData,它将自动更新数据并触发重绘。
其次,您正在尝试使用由parse返回的图像,但是parse从不返回图像(至少不是直接返回)。因此,访问object[@"imageFile"]将返回一个PFFile,而不是一个UIImage。您需要先调用getDataInBackgroundWithBlock:获取图片数据,然后才能使用。
https://stackoverflow.com/questions/22890380
复制相似问题