为什么没有将此对象添加到此数组中?

时间:2013-07-29 00:11:26

标签: iphone ios objective-c

我有一个方法可以生成PFObject并将其存储在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);
}

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

1 个答案:

答案 0 :(得分:3)

确保您正在初始化阵列。

listings = [[NSMutableArray alloc] init];
相关问题