ios - NS无效参数异常 : App crashes upon opening

标签 ios parse-platform pfquery

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

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

崩溃信息是:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* setObjectForKey: object cannot be 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];
 }

知道为什么会崩溃吗?

最佳答案

您的数组 self.usersToDisplay 中的值似乎没有有效的查询对象。

来自解析文档:

If you want to retrieve objects matching several different values, you can use whereKey:containedIn:, providing an array of acceptable values. This is often useful to replace multiple queries with a single query. For example, if you want to retrieve scores made by any player in a particular list:

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

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

干杯!

关于ios - NS无效参数异常 : App crashes upon opening,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32418833/

相关文章:

iOS 推送通知无法使用 Phonegap-plugin-push 通过 GCM 工作

ios - 在 Swift 中使用 UITableView 以编程方式切换 View

ios - 为什么每次都会返回相同的时间戳,除非我重新构建并运行应用程序?

ios - HeaderView 和 FooterView、Xib、StoryBoard

ios - 当特定用户发帖时解析推送通知

ios - 从Parse.com中的用户类删除对象

iOS + Parse Cloud Code - 更新特定用户(未登录用户)

ios - 解析查询后重新加载 tableView(串行队列?)

parse-platform - 在 Parse.com 中使用指针用户查询

swift - 仅使用用户的 objectId 检索用户的数据 - Parse & Swift