- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我收到错误 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;
}
现在您可以使用调试器查看 image1
、image2
、image3
或 image4
是否正确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/
检查我的 iOS6 应用程序并尝试为 iOS7 修复所有问题。在我的整个应用程序中,我遇到了错误: -[__NSPlaceholderDictionary initWithObjects:forKey
我有以下代码: queryParams = @{@"geo_location" : [GlobalData sharedGlobalData].latLong, @"sale_ids": select
我正在尝试在 iOS 上使用电子邮件和密码进行简单登录。登录时出现以下错误。 Terminating app due to uncaught exception 'NSInvalidArgumentE
我正在使用 NSMutableUrl 请求从 .net Web 服务器获取 Web 数据。 在通过使用 NSXmlparsing 解析响应将我存储在 NSDirectory 中之后,我正在使用肥皂请求
我有一个 UITextView,我想将此文本存储在 NSDictionary 中。 我有这段代码: var imageData = UIImageJPEGRepresentation(photoIn
我正在尝试使用 Pandas UDFs (a.k.a. Vectorized UDFs)在 macOS 10.14.3 (macOS Mojave) 上的 Apache Spark 2.4.0 中。
我在 crashlytics 报告中发现了此崩溃,并且这只发生在 iPhone 7(iOS 13.*) 中。我也尝试在模拟器和真实设备中调试此崩溃,但它在我的任何设备中都没有崩溃。我不知道该怎么办才能
我收到错误 NSInvalidArgumentException 这是我的模型类 +(NSArray *)users { NSDictionary *user1 = @{@"username"
我的 Storyboard中有两个 UITextField,用于接收用户输入的数字,minPrice 和 maxPrice。当我在模拟器中点击提交时,应用程序崩溃并且我收到以下错误: Terminat
我在尝试将数据传递给 Obj-C 方法时遇到错误。 代码如图,Obj-C: RCT_EXPORT_METHOD(connect:(NSDictionary *) params) { _conn
我是一名优秀的程序员,十分优秀!