给定以下界面:
@interface DetailViewController ()
@property (nonatomic, strong) NSDictionary *contentTypeToString;
@property (nonatomic, strong) NSDictionary *contentTypeToContent;
@property (nonatomic, strong) NSArray *contentDestcriptors;
@property (nonatomic, strong) NSArray *content;
@end
以及以下方法:
- (void)viewDidLoad
{
[super viewDidLoad];
//dumb data
self.contentTypeToString =@{
[NSNumber numberWithInt:ContextTypePlace] : @"Place",
[NSNumber numberWithInt:ContextTypeDate] : @"Date",
[NSNumber numberWithInt:ContextTypeTime] : @"Time",
[NSNumber numberWithInt:ContextTypeWeather] : @"Weather",
[NSNumber numberWithInt:ContextTypeSeason] : @"Season",
[NSNumber numberWithInt:ContextTypeTimeOfDay] : @"Time of Day",
[NSNumber numberWithInt:ContextTypePlace] : @"Place",
};
self.contentTypeToContent = @{
[NSNumber numberWithInt:ContextTypePlace] : @"Dublin",
[NSNumber numberWithInt:ContextTypeDate] : @"21.12.2012",
[NSNumber numberWithInt:ContextTypeTime] : @"21:32",
[NSNumber numberWithInt:ContextTypeWeather] : @"Cloudy",
[NSNumber numberWithInt:ContextTypeSeason] : @"Winter",
[NSNumber numberWithInt:ContextTypeTimeOfDay] : @"Evening",
[NSNumber numberWithInt:ContextTypePerson] : @"John, Ann",
};
self.contentDestcriptors = [self.contentTypeToString allValues];
self.content = [self.contentTypeToContent allValues];
}
我得到:
由于未捕获的异常而终止应用程序NSRangeException
,原因:*** -[__NSArrayI objectAtIndex:]: index 6 beyond bounds [0 .. 5]
Tf 我注释掉我使用 allValues 方法的地方,代码工作正常。文字中的错误,还是我的错?