gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:14:03 26 4
gpt4 key购买 nike

我正在尝试构建一个应用程序,用户可以在其中喜欢和评论帖子,这很像 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com