我知道如何在视图控制器之间传输数据,但是在我能够完成解析查询之前传输数据因此在视图控制器之间传输数据时数据丢失了。 我使用的代码如下。第一部分与解析查询相关,最后一部分详细说明数据发送。如何在将数据传递到新视图之前将数据成功存储在phoneNUMBERS中?因为此刻被传递为NULL。
NSMutableArray *phoneNUMBERS = [NSMutableArray new];
// Initialize table data
PFQuery *query = [PFQuery queryWithClassName:@"friendsAssociation"];
//quesrys the class Friend asssociation to find when instances of "user" equal the
//logged in user's username
[query whereKey:@"user" equalTo:usernamecontrol];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d users.", objects.count);
// Do something with the found objects
if (objects.count == 0) {
//uialert letting the user know that no phone number matches the query
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No User"
message:@"No user matches this username"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
//if there is only one number matching the query
if (objects.count >=1) {
int i=0;
for (PFObject *object in objects) {
NSLog(@"%@", objects[i]);
NSString *phonenumber = object[@"phoneNumber"];
NSLog(@"%@", phonenumber);
[phoneNUMBERS addObject:phonenumber];
}
NSLog(@"%@", phoneNUMBERS[1]);
//if there is more than one phonenumber matching the query as
//the user to input the friends username
//instead
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}}];
ContactTableViewController *contacts = [[ContactTableViewController alloc]initWithNibName:Nil bundle:Nil];
contacts.user = usernamecontrol;
contacts.PHONENUMBERS = phoneNUMBERS;
[self presentViewController:contacts animated:YES completion:Nil];
答案 0 :(得分:1)
哟需要把这部分代码
ContactTableViewController *contacts = [[ContactTableViewController alloc]initWithNibName:Nil bundle:Nil];
contacts.user = usernamecontrol;
contacts.PHONENUMBERS = phoneNUMBERS;
[self presentViewController:contacts animated:YES completion:Nil];
进入完成块的“成功”部分。冰。在
之后// Do something with the found objects
在if
的下一行之前。