Sam*_*D20 6 objective-c uitableview ios parse-platform
我有一个UITableViewController负责显示满员的桌子.此数据存储在parse.com上的数据库中.
这是我的UITableViewController,我刚开始商店:
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nil bundle:nil];
if(self){
store = [[EmployeeStore alloc] init];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
这是EmployeeStoreinit方法,我在其中查询员工:
-(id) init{
self = [super init];
if(self){
employees = [[NSMutableArray alloc] init];
[self fetchEmployeesFromDatabase];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
fetchEmployeesFromDatabase,我在那里查询员工.
-(void) fetchEmployeesFromDatabase{
PFQuery *query = [PFQuery queryWithClassName:@"Employee"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d scores.", objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"%@", object.objectId);
[employees addObject:object];
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
Run Code Online (Sandbox Code Playgroud)
我成功地接收了它们,但是问题是查询发生在后台,并且直到表视图加载完成后才完成,因此表视图不会填充.我需要让表在查询完成后重新加载其数据,但我该怎么做呢?
iCo*_*der 11
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nil bundle:nil];
if(self){
store = [[EmployeeStore alloc] init];
store.tableView = self.tableView;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
@property (nonatomic, strong) UITableView *tableView;
Run Code Online (Sandbox Code Playgroud)
-(id) init{
self = [super init];
if(self){
employees = [[NSMutableArray alloc] init];
[self fetchEmployeesFromDatabase];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
和fetchEmployeesFromDatabase
-(void) fetchEmployeesFromDatabase{
PFQuery *query = [PFQuery queryWithClassName:@"Employee"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d scores.", objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"%@", object.objectId);
[employees addObject:object];
}
dispatch_async(dispatch_get_main_queue(), ^ {
[self.tableView reloadData];
});
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5919 次 |
| 最近记录: |