在看似无关的方法中的预期表达?

时间:2014-03-31 20:10:16

标签: ios xcode methods

我有两种方法,第二种方法是空的,因为我还没有填写代码。我的问题是,第一个表达式中的最后几行代码似乎打破了第二个代码,尽管我无法想到它们完全不相关的原因。我在第二种方法的IBAction下出现expected expression错误。

- (IBAction)showResultsFromYesterday:(id)sender {

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *todayComponents = [NSDateComponents new];
todayComponents.year = 2014;
todayComponents.month = 2;
todayComponents.day = 16;
todayComponents.hour = 4;
todayComponents.minute = 59;
todayComponents.second = 50;

NSDate *today = [calendar dateFromComponents:todayComponents];

NSDateComponents *offset = [NSDateComponents new];
offset.day = -1;
NSDate *yesterday = [calendar dateByAddingComponents:offset toDate:today options:0];

PFQuery *yesterdayUserCountQuery = [PFUser query];
[yesterdayUserCountQuery whereKey:@"createdAt" greaterThanOrEqualTo:yesterday];
[yesterdayUserCountQuery countObjectsInBackgroundWithBlock:^(int userCount, NSError *error) {
    if (!error) {
        // The count request succeeded. Log the count
        //     NSLog(@"There are %d users", userCount);
    } else {
        // The request failed
    }
    NSString *yesterdayNumberOfUsers = [[NSString alloc]initWithFormat:@"%d", userCount ];
    self.numberOfUsers.text = yesterdayNumberOfUsers;
}

- (IBAction)showResultsFromLastWeek:(id)sender {


}

当我删除PFQuery的所有代码时,错误消失了。我不知道为什么它会导致其他方法出错。

1 个答案:

答案 0 :(得分:2)

您没有关闭传递给countObjectsInBackgroundWithBlock:的区块。您需要结束}