NSInvalidArgumentException:应用程序在打开时崩溃

时间:2015-09-06 00:13:54

标签: ios parse-platform pfquery

我正在尝试构建一个用户可以喜欢的应用和评论帖子,很像Instagram。所有帖子/喜欢/评论都保存在parse.com上!我已经能够将代码放在一起,这应该像在示例应用程序上一样工作但是当我移动文件时,这段代码会使它崩溃:

 [query whereKey:@"user" containedIn:self.usersToDisplay];

崩溃讯息是:

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* setObjectForKey:object不能为nil(key:$ in)'**

其余的代码如下:

- (void)viewDidLoad
{
// self.usersToDisplay = @[[PFUser currentUser]];

self.parseClassName = @"Photo";
[super viewDidLoad];

self.tableView.layer.cornerRadius = 10;
self.tableView.layer.masksToBounds = YES;
}

- (void)setUsersToDisplay:(NSArray *)usersToDisplay {
_usersToDisplay = usersToDisplay;

if (self.isViewLoaded)
{
    [self loadObjects];
}
}


  - (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

// If Pull To Refresh is enabled, query against the network by default.
if (self.pullToRefreshEnabled) {
    query.cachePolicy = kPFCachePolicyNetworkOnly;
}

 [query whereKey:@"user" containedIn:self.usersToDisplay];
[query addDescendingOrder:@"createdAt"];
return query;
}

 -(PFTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
  {
   PhotoViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ImageCellReuseID"];
if(!cell)
{
    cell = [[PhotoViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"ImageCellReuseID"];
}

cell.imageView.file = object[@"image"];
[cell.imageView loadInBackground];

NSDateFormatter* formatter = [NSDateFormatter new];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateStyle:NSDateFormatterShortStyle];
NSString* uploaded = [formatter stringFromDate:object.createdAt];

cell.textLabel.text = [NSString stringWithFormat:@"Taken By %@ ", object[@"username"]];

cell.detailTextLabel.text = uploaded;

return cell;
}


  -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  [self performSegueWithIdentifier:@"ShowDetail" sender:indexPath];
 }

知道它崩溃的原因吗?

1 个答案:

答案 0 :(得分:1)

它看起来像数组self.usersToDisplay中的一个值没有查询的有效对象。

从解析文档:

  

如果要检索与多个不同值匹配的对象,可以使用whereKey:containedIn:,提供可接受值的数组。这通常可用于使用单个查询替换多个查询。例如,如果您想要检索特定列表中任何玩家所做的分数:

// Finds scores from any of Jonathan, Dario, or Shawn
// Using PFQuery
NSArray *names = @[@"Jonathan Walsh", @"Dario Wunsch", @"Shawn Simon"]; 
[query whereKey:@"playerName" containedIn:names];

确保数组中的所有值都与数据库中的值匹配。

干杯!

相关问题