我有一个方法可以生成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);
}
在最后一行,我让控制台打印存储在列表中的对象数量,但它重复打印为零。我哪里错了?
答案 0 :(得分:3)
确保您正在初始化阵列。
listings = [[NSMutableArray alloc] init];