Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
我有两种方法,第二种是空的,因为我还没有填写代码。我的问题是,尽管我想不出它们完全无关的原因,但第一个表达式中的最后几行代码似乎破坏了第二个代码。我在第二种方法的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的所有代码时,错误消失了。我不知道为什么它会导致其他方法出错。

最佳答案

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

09-27 12:44