【发布时间】:2014-06-13 00:27:51
【问题描述】:
我是 Objective-C 的初学者,在字典和数组方面确实有点吃力。
我的目标是创建一个表格视图,其中每个单元格都包含来自服务器的图片。图片的 url 来自 JSON 调用。我从 Apple 下载了名为“lazy table view”的示例,并尝试将其与我在 Standford iOS Class 中找到的示例合并。到目前为止一切正常,除了图片。一旦我尝试访问该图标,Xcode 就会引发以下异常:
-[__NSCFDictionary Icon]: unrecognized selector sent to instance 0x10b845ff0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary Icon]: unrecognized selector sent to instance 0x10b845ff0'
有问题的代码如下所示:
@interface FlickrPhotosTVC : UITableViewController
@property (nonatomic, strong) NSArray *photos;
@end
@interface ClRecord : NSObject
@property (nonatomic, strong) UIImage *Icon;
#define FLICKR_PHOTO_TITLE @"title"
ClRecord *clRecord = self.photos[indexPath.row];
cell.textLabel.text = [clRecord valueForKeyPath:FLICKR_PHOTO_TITLE]; // works
if (clRecord.Icon) NSLog(@"test"); // throws exeption
这似乎与类型有关。尝试访问数组,同时访问字典或类似内容。我在堆栈上找到了一些相关的帖子,但目前无法解决。
感谢您的帮助!
【问题讨论】:
-
最近发现这篇文章,你可能会觉得有用...rypress.com/tutorials/objective-c/data-types/nsdictionary.html
标签: ios objective-c exception nsarray nsdictionary