我有一個調用此函數並調用performSegueWithIdentifier的按鈕。 Segue發生在數據是兩個查詢返回數據之前。我該如何解決這個問題?將從Cloudkit提取的數據從一個視圖控制器傳遞到另一個視圖控制器
-(void)recommendSomeone {
NSString *currentUserID = [NSString stringWithFormat:@"%@%@",@"KU",self.liaResponse[@"id"]];
CKContainer *myContainer = [CKContainer defaultContainer];
CKDatabase *publicDatabase = [myContainer publicCloudDatabase];
CKRecordID *currentUserRecordID = [[CKRecordID alloc] initWithRecordName:currentUserID];
CKReference *recordToMatch = [[CKReference alloc] initWithRecordID:currentUserRecordID action:CKReferenceActionNone];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"contactList CONTAINS %@",recordToMatch];
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"knotworkGhostUsers" predicate:predicate];
[publicDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {
if (error) {
// Error handling for failed fetch from public database
NSLog(@"error querying knotwork users %@", error);
}
else {
// Display the fetched records
self.randomGhostUser = results[arc4random_uniform([results count])];
NSLog(@"this is the first name %@", self.randomGhostUser[@"firstname"]);
NSLog(@"knotwork ghost users for current user data returned ordinary title %@",results);
NSString* searchQuery = @" ";
NSString *kuTitle = [self.randomGhostUser[@"title"] lowercaseString];
NSArray *keyWords = @[@"developer",@"networking",@"sales manager",@"engineer",@"doctor",@"facility manager"];
for(NSString* keyWord in keyWords){
NSRange checkResult = [kuTitle rangeOfString:keyWord];
if(checkResult.location != NSNotFound){
searchQuery = [NSString stringWithFormat:@"%@%@%@",searchQuery,@" ",keyWord];
}
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"allTokens tokenmatches[cdl] %@ AND contactList CONTAINS %@",searchQuery,recordToMatch];
CKQuery *query2 = [[CKQuery alloc] initWithRecordType:@"knotworkGhostUsers" predicate:predicate];
[publicDatabase performQuery:query2 inZoneWithID:nil completionHandler:^(NSArray *response, NSError *error) {
if (error) {
// Error handling for failed fetch from public database
NSLog(@"error querying knotwork users %@", error);
}
else {
// Display the fetched records
self.recommendedGhostUser = response;
NSLog(@"knotwork users data returned after recom %@", self.recommendedGhostUser);
}
}];
}
[self performSegueWithIdentifier:@"Recommend" sender:nil];
}];
} 強調文本
你似乎忘了問一個問題。 – 2015-02-05 17:39:00
通常情況下,您將在prepareForSegue中傳遞數據。你有沒有試圖實現這一點?關於在控制器之間傳遞數據,SO上有數百個答案,您應該進行一些搜索。 – rdelmar 2015-02-05 17:44:08
我試着將數據傳遞給prepareForSegue。但問題仍然是,在數據提取之前發生prepareForSegue – onyemmeme 2015-02-05 18:10:26