0
我从我的Parse类返回一些对象到UITableView。从Parse.com返回对象时,setObjectForKey:object不能为零
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: $in)
下面是我在做它:
@implementation MessageViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self refresh];
_favorited = [[NSMutableArray alloc] initWithCapacity:1000];
}
- (void)refresh {
NSArray *favorite_ids = [PFUser currentUser][@"favorites"];
PFQuery *query = [PFQuery queryWithClassName:@"Messages"];
[query whereKey:@"objectId" containedIn:favorite_ids];
[query findObjectsInBackgroundWithBlock:^(NSArray *projects, NSError *error) {
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
}
PFQuery *query = [PFQuery queryWithClassName:@"MoreMessages"];
[query whereKey:@"objectId" containedIn:favorite_ids];
[query findObjectsInBackgroundWithBlock:^(NSArray *companies, NSError *error) {
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
}
[_favorited setArray:[projects arrayByAddingObjectsFromArray:companies]];
NSLog(@"%@", _favorited);
[_refreshControl endRefreshing];
[self.tableView reloadData];
[SVProgressHUD dismiss];
}];
}];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (_favorited.count < 0) {
return 1;
}
return self.favorited.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (_favorited.count < 0) {
return 127;
}
return 65;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (_favorited.count < 0) {
NoFavoritesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NoFavoritesTableViewCell"];
return cell;
}
MessagesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessagesTableViewCell"];
_favoritedObject = [_favorited objectAtIndex:indexPath.row];
[(PFFile*)_favoritedObject[@"profilePic"] getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
cell.profilePic.image = [UIImage imageWithData:data];
}];
cell.name.text = _favoritedObject[@"name"];
return cell;
}
@end
也许尝试调试代码,看看它死在什么行,什么变量是零当时? –
尝试显示项目和公司阵列..公司越来越无我想..通过调试代码来检查它..! – Vidhyanand
请添加一个异常断点,运行它并更新问题(或者仅在空列周围添加防御性代码)。如果不考虑这个或@PhillipMills的建议,这个问题就有可能在“为什么这段代码无法正常工作”的基础上结束。 – danh