从pfquery中获取int值以更改设置objective-c

时间:2016-02-23 20:55:10

标签: objective-c parse-platform

我试图使用目标ci中想要创建一个int的脚本,我可以访问整个视图,加载更改设置或视图控制器,但它不像swift一样工作,我得到一个null pfquery所以我试图创建一个数组,并且也无法从查询中获取任何内容

设置和变量的最佳方法是什么,并在pfquery中设置它,然后再使用if语句

这是我的一些代码

__block int setting = 0;

PFQuery *query = [PFQuery queryWithClassName:@"test"];
[query whereKey:@"testActive" equalTo:[NSNumber numberWithBool:YES]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded.
        NSLog(@"Successfully retrieved %lu scores.", (unsigned long)objects.count);
        // Do something with the found objects
        for (PFObject *object in objects) {
            NSLog(@"%@", object.objectId);
             setting = [[object objectForKey:@"testSetting"] intValue];
         // When checked in the loop i get all the right data   
        }
    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];

// When checked here i get settings = 0 when it should be 1
if (setting == 0) {
     self.segmentedControl.selectedSegmentIndex = 0;

} else if (setting == 1) {
    self.segmentedControl.selectedSegmentIndex = 1;
}

if (setting == 3) {
    [self.segmentedControl setEnabled:YES];
}else {
    [self.segmentedControl setEnabled:NO];
}

但是当我检查设置int时它始终为0但是如果我登录循环会给我正确的数字

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

感谢您的帮助,但我想出来了......

在我执行if语句之前,

findObjectsInBackgroundWithBlock没有完成

所以我将代码移动到一个新函数中,我在PFQuery完成时运行,给我正确的int