ios - 将 nil 图像插入 NSMutableDictionary

标签 ios objective-c

iOS 似乎不允许将 nil 图像插入 NSDictionary。我可以给它一个 nil 图片吗?

我的 NSDictionary 设置如下:

NSDictionary *record = [NSDictionary dictionaryWithObjectsAndKeys:
   UIImageJPEGRepresentation(self.mainImage.image, 1.0), @"tagData", 
   self.firstname, @"firstname", 
   self.lastname, @"lastname", nil];

我要插入的数据

NSDictionary1 contains NSString(Fabian), NSString(Toulouse), NSData(JPGFILE)
NSDictionary2 contains NSString(Kindle), NSString(May)     , NSData()
NSDictionary3 contains NSString(Far)   , NSString(Ney)     , NSData(JPGFIle)
NSDictionary4 contains NSString(Here)  , NSString(There)   , NSData()
NSDictionary5 contains NSString(Sam)   , NSString(Sung)    , NSData()
NSDictionary6 contains NSString(IBM)   , NSString(HP)      , NSData(JPGFIle)

Tableview 显示上面的数据集。

S/no    First Name    Last Name       Image
 1        Fabian       Toulouse       JPGFILE   
 2        Kindle       May            PNGFILE
 3        Far          Ney            JPGFIle
 2
 2
 6        IBM          HP             JPGFIle

我尝试了以下

NSDictionary *record = [NSDictionary dictionaryWithObjectsAndKeys:
   Nil, @"tagData", 
   self.firstname, @"firstname", 
   self.lastname, @"lastname", nil];

NSDictionary *record = [NSDictionary dictionaryWithObjectsAndKeys:
   Null, @"tagData", 
   self.firstname, @"firstname", 
   self.lastname, @"lastname", nil];

但它们不起作用。

有什么建议吗?

最佳答案

您需要使用 [NSNull null] 来表示集合中的 nil 值。 nill/null 将引发异常

关于ios - 将 nil 图像插入 NSMutableDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23556636/

相关文章:

iphone - 使用 CGContext 显示 iPhone 的 Sprite 表

ios - 带有 xib 文件和自定义构造函数的自定义 UITableViewCell

ios - 使用按钮显示来自 JSON 的文本

iphone - 如何拉伸(stretch)单元格背景图像而不像 iPhone 中的聊天气泡那样的特定部分?

ios - 在 Swift 中使用 value 参数时 genstrings 会阻塞

objective-c - 如何判断 NSData 是否实际上是 NSImage?

objective-c - 使用ReactiveCocoa时如何不使用flattenMap直接订阅signal的信号?

iphone - 可以从 Application Delegate 使用 UIActionSheet 吗?

ios - UIScrollView 内部的 UIScrollView : Scrolling

ios - Xcode 6 : Label in Table Cell won't expand/display longer text upon expansion/line up with cell