gpt4 book ai didi

IOS FindObjectsInBackgroundWithBlock -> setNeedsDisplay

转载 作者:行者123 更新时间:2023-11-29 12:48:57 26 4
gpt4 key购买 nike

我正在运行一个 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");
}

最佳答案

您有几个不同的问题。

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

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com