Uitableview 从plist setObjectForKey加载图像:对象不能为零(键:图像)错误

Uitableview 从plist setObjectForKey加载图像:对象不能为零(键:图像)错误,uitableview,Uitableview,请问,有人能帮我解决我在Xcode 5中练习IOS应用程序时遇到的这个错误吗 2014-03-16 14:10:44.072 TabCreator[563:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: image). 加载到images.xcsets中的图像和我创建了

请问,有人能帮我解决我在Xcode 5中练习IOS应用程序时遇到的这个错误吗

2014-03-16 14:10:44.072 TabCreator[563:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: image).
加载到images.xcsets中的图像和我创建了一个plist文件,并尝试使用plist中的数组填充UITableView,如下所示:

<plist version="1.0">
<array>
    <dict>
        <key>pic</key>
        <string>skyline.png</string>
        <key>name</key>
        <string>Skyline</string>
        <key>datecreated</key>
        <date>1975-06-03T23:00:00Z</date>
    </dict>
    <dict>
        <key>pic</key>
        <string>hummer.png</string>
        <key>name</key>
        <string>Hummer</string>
        <key>datecreated</key>
        <date>1963-12-18T00:00:00Z</date>
    </dict>

    </array>
</plist>

照片
skyline.png
名称
空中轮廓线
日期创建
1975-06-03T23:00:00Z
照片
hummer.png
名称
悍马
日期创建
1963-12-18T00:00:00Z
我的HomeviewController.m文件是:

@interface HomeViewController ()
@property   (nonatomic,strong)NSMutableArray *functions;
@end

@implementation FTHomeViewController

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {

        NSString *plistPath =[[NSBundle mainBundle]pathForResource:@"functions" ofType:@"plist"];
        NSArray *nonMutableFunctions = [NSArray arrayWithContentsOfFile:plistPath];

        self.functions = [NSMutableArray array];

        NSMutableDictionary *function;
        NSDictionary *dictionary;
        NSString *name;
        NSString *pic;
        UIImage *image;
        NSDate *datecreated;

        for (int i=0; i<[nonMutableFunctions count]; i++) {
            dictionary = [nonMutableFunctions objectAtIndex:i];
            name=dictionary[@"name"];
            pic=dictionary[@"pic"];
            image=[UIImage imageNamed:pic];
            datecreated =dictionary[@"datecreated"];
            function = [NSMutableDictionary dictionary];

            function[@"name"]=name;
            function[@"image"]=image;
            function[@"datecreated"]=datecreated;

            [self.functions addObject:function];
        }
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"];

    NSMutableDictionary *function=self.functions[indexPath.row];

    NSString *name =function[@"name"];
    NSDate *datecreated = function[@"datecreated"];
    UIImage *image = function[@"image"];

    cell.textLabel.text = name;
    cell.detailTextLabel.text = datecreated.description;
    cell.imageView.image = image;

    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.functions count];
}

//Deselect selected row when selected

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
@接口HomeViewController()
@属性(非原子,强)NSMutableArray*函数;
@结束
@HomeViewController的实现
-(id)initWithCoder:(NSCoder*)aDecoder
{
self=[super initWithCoder:aDecoder];
如果(自我){
NSString*plistPath=[[NSBundle mainBundle]pathForResource:@“plist”类型的“函数”;
NSArray*非可变函数=[NSArray arrayWithContentsOfFile:plistPath];
self.functions=[NSMutableArray];
NSMutableDictionary*函数;
NSDictionary*字典;
NSString*名称;
NSString*pic;
UIImage*图像;
NSDate*创建日期;

对于(int i=0;i当我在预览中从jpg导出到png时,只是简单地省略了png扩展名。必须保留扩展名,因为绘图文件包含完整的文件名,包括扩展名。

基本上,它告诉您的是UIImage没有被创建,而image变量中有nil。请检查图片,dictionary和nonMutableFunctions变量。很抱歉回复晚了。感谢Krafter,我不得不调试它,并发现确实图像变量为nil,尽管plist文件确实进行了解析。我不得不做一些挖掘,并发现Xcode 5 images.xcsets实际上不接受.JPG图像扩展名,所以必须在不隐藏ext的情况下进行预览并导出到.PNG这很有效。无论如何,谢谢你的意见。我不知道JPG images.xcsets的问题。谢谢你让我知道。你可能想为这个问题添加一个答案。