Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UITableViewCell在设置单元格项上的文本时生成异常_Uitableview_Nsdictionary - Fatal编程技术网

UITableViewCell在设置单元格项上的文本时生成异常

UITableViewCell在设置单元格项上的文本时生成异常,uitableview,nsdictionary,Uitableview,Nsdictionary,我在cellForRowAtIndexPath中使用以下代码,当我在UILabel中填充数据时,它发送错误 NSDictionary *benchmarkDictionary = (NSDictionary *)[benchmarkArray objectAtIndex:indexPath.row]; ((UILabel *)[cell viewWithTag:15]).text = [benchmarkDictionary objectForKey:@"benchmarkTitle"]; (

我在cellForRowAtIndexPath中使用以下代码,当我在UILabel中填充数据时,它发送错误

NSDictionary *benchmarkDictionary = (NSDictionary *)[benchmarkArray objectAtIndex:indexPath.row];

((UILabel *)[cell viewWithTag:15]).text = [benchmarkDictionary objectForKey:@"benchmarkTitle"];
((UILabel *)[cell viewWithTag:16]).text = [benchmarkDictionary objectForKey:@"benchmarkDescription"];
例外情况是: -[基准objectForKey:]:发送到实例0x75d59c0的选择器无法识别 2013-03-08 16:21:39.515 Fdtrainer[2719:11303]*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[Benchmark objectForKey:]:未识别的选择器发送到实例0x75d59c0'

我的基准课程是:

@interface Benchmark : NSObject

@property (nonatomic, retain) NSString *bid;
@property (nonatomic, retain) NSString *benchmarkTitle;
@property (nonatomic, retain) NSString *benchmarkDescription;

-(id)initWithCoder: (NSCoder *)coder;
-(void)encodeWithCoder:(NSCoder *)encoder;

@end

@implementation Benchmark

@synthesize bid;
@synthesize benchmarkTitle;
@synthesize benchmarkDescription;

- (id) initWithCoder:(NSCoder *)coder {

    self = [super init];
    if(self) {
        bid = [coder decodeObjectForKey:@"id"];
        benchmarkTitle = [coder decodeObjectForKey:@"benchmarkTitle"];
        benchmarkDescription = [coder decodeObjectForKey:@"benchmarkDescription"];
    }
    return self;
}

- (void) encodeWithCoder:(NSCoder *)encoder {

    [encoder encodeObject:bid forKey:@"id"];
    [encoder encodeObject:benchmarkTitle forKey:@"benchmarkTitle"];
    [encoder encodeObject:benchmarkDescription forKey:@"benchmarkDescription"];
}

@end

我猜您以错误的方式访问您的财产:

试试这个:

@interface Benchmark : NSObject

@property (nonatomic, retain) NSString *bid;
@property (nonatomic, retain) NSString *benchmarkTitle;
@property (nonatomic, retain) NSString *benchmarkDescription;

-(id)initWithCoder: (NSCoder *)coder;
-(void)encodeWithCoder:(NSCoder *)encoder;

@end

@implementation Benchmark

@synthesize bid = _bid;
@synthesize benchmarkTitle = _benchmarkTitle;
@synthesize benchmarkDescription = _benchmarkDescription;

- (id) initWithCoder:(NSCoder *)coder {

self = [super init];
if(self) {
    _bid = [coder decodeObjectForKey:@"id"];
    _benchmarkTitle = [coder decodeObjectForKey:@"benchmarkTitle"];
    _benchmarkDescription = [coder decodeObjectForKey:@"benchmarkDescription"];
}
return self;
}

- (void) encodeWithCoder:(NSCoder *)encoder {

[encoder encodeObject:_bid forKey:@"id"];
[encoder encodeObject:_benchmarkTitle forKey:@"benchmarkTitle"];
[encoder encodeObject:_benchmarkDescription forKey:@"benchmarkDescription"];
}

似乎下面这行代码可能会导致问题

NSDictionary *benchmarkDictionary = (NSDictionary *)[benchmarkArray objectAtIndex:indexPath.row];
您确定benchmarkArray中包含NSDictionary吗。把某样东西扔到字典里不会使它成为字典。benchmarkArray似乎包含基准对象,它属于NSObject类型,并且它们不响应objectForKey选择器