gpt4 book ai didi

ios - NSInvalidArgumentException',reas-[__NSPlaceholderDictionary initWithObjects :forKeys:count:]: attempt to insert nil object from objects[4]'

转载 作者:IT王子 更新时间:2023-10-29 07:52:48 26 4
gpt4 key购买 nike

我收到错误 NSInvalidArgumentException 这是我的模型类

+(NSArray *)users
{
NSDictionary *user1 = @{@"username" : @"master photographer", @"email" : @"worldtravel@me.com", @"password" : @"drowssap", @"age" : @24, @"profilePicture" : [UIImage imageNamed:@"person1.jpeg"]};
NSDictionary *user2 = @{@"username" : @"Lots of tots", @"email" : @"otterskips@me.com", @"password" : @"icecreamrocks", @"age" : @65, @"profilePicture" : [UIImage imageNamed:@"person2.jpeg"]};
NSDictionary *user3 = @{@"username" : @"iTechie", @"email" : @"theRealApple@me.com", @"password" : @"infiniteloop", @"age" : @30, @"profilePicture" : [UIImage imageNamed:@"person3.jpeg"]};
NSDictionary *user4 = @{@"username" : @"Royal", @"email" : @"king@me.com", @"password" : @"IGotAPalace", @"age" : @0, @"profilePicture" : [UIImage imageNamed:@"person4.jpeg"]};

NSArray *userArray = @[user1, user2, user3, user4];
return userArray;
}

@end

这是我的 viewdidload

self.users = [DMZUserData users];
NSLog(@"%@", self.users);

最佳答案

该错误意味着您正试图将 nil 放入字典中(这是不允许的)。由于您正在使用字符串文字构建字典,因此它们不能为 nil。这意味着问题出在您的一张或多张图片上。

试试这个来帮助找到问题:

+(NSArray *)users
{
UIImage *image1 = [UIImage imageNamed:@"person1.jpeg"];
UIImage *image2 = [UIImage imageNamed:@"person2.jpeg"];
UIImage *image3 = [UIImage imageNamed:@"person3.jpeg"];
UIImage *image4 = [UIImage imageNamed:@"person4.jpeg"];

NSDictionary *user1 = @{@"username" : @"master photographer", @"email" : @"worldtravel@me.com", @"password" : @"drowssap", @"age" : @24, @"profilePicture" : image1 };
NSDictionary *user2 = @{@"username" : @"Lots of tots", @"email" : @"otterskips@me.com", @"password" : @"icecreamrocks", @"age" : @65, @"profilePicture" : image2 };
NSDictionary *user3 = @{@"username" : @"iTechie", @"email" : @"theRealApple@me.com", @"password" : @"infiniteloop", @"age" : @30, @"profilePicture" : image3 };
NSDictionary *user4 = @{@"username" : @"Royal", @"email" : @"king@me.com", @"password" : @"IGotAPalace", @"age" : @0, @"profilePicture" : image4 };

NSArray *userArray = @[user1, user2, user3, user4];
return userArray;
}

现在您可以使用调试器查看 image1image2image3image4 是否正确nil 或为每个添加 NSLog 语句。

请记住,文件名区分大小写,因此请确保您传递给 imageNamed: 的名称与真实文件名完全匹配。还要验证图像的扩展名为 jpeg 而不是 jpg。确保图像被打包到您的资源包中。

关于ios - NSInvalidArgumentException',reas-[__NSPlaceholderDictionary initWithObjects :forKeys:count:]: attempt to insert nil object from objects[4]',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23298615/

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