0

我有一个方法可以生成 aPFObject并将其存储在NSMutableArray. 然后一个 tableview 用这个数组填充自己。但是,存储 的方法PFObject没有成功添加对象。这是方法:

- (void)addListing{
    PFObject* userListing = [PFObject objectWithClassName:@"userListing"];
    [userListing setObject:[NSString stringWithFormat:@"John Smith"] forKey:@"userName"];
    [userListing setObject:[NSString stringWithFormat:@"408 521 3322"] forKey:@"userPhoneNumber"];
    [userListing setObject:[NSString stringWithFormat:@"Lorem Ipsum Dolor Sit Amet"] forKey:@"listingName"];
    [userListing setObject:[NSString stringWithFormat:@"$10"] forKey:@"listingPrice"];

    [listings addObject:userListing]; 
    [userListing saveInBackground];

    NSLog(@"%i", listings.count);
}

在最后一行,我让控制台打印存储在列表中的对象数量,但它重复打印为零。我哪里错了?

4

1 回答 1

3

确保您正在初始化数组。

listings = [[NSMutableArray alloc] init];
于 2013-07-29T00:15:02.640 回答