【发布时间】:2011-12-25 22:26:30
【问题描述】:
这是我的代码:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *str = [[[NSString alloc] initWithData:buffer encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"str: %@",str);
NSDictionary *dict = [str JSONValue];
NSDateFormatter *fmt = [[[NSDateFormatter alloc] init] autorelease];
[fmt setDateFormat:@"yyyy-MM-dd"];
NSArray *array = [[dict objectForKey:@"event"] retain];
NSLog(@"Array: %@",array);
for (NSDictionary *tempdict in array)
{
NSDate *d = [fmt dateFromString:[tempdict objectForKey:@"eve_date"]];
NSLog(@"Date %@",d);
NSLog(@"Date of event %@",[tempdict objectForKey:@"eve_date"]);
NSDate *t =[tempdict objectForKey:@"eve_date"];
NSLog(@"Date of t %@",t);
NSLog(@"This is title_event %@",[tempdict objectForKey:@"title"]);
NSLog (@"Time of event %@", [tempdict objectForKey:@"eve_time"]);
NSLog(@"This is description %@",[tempdict objectForKey:@"description"]);
[eventPHP addObject:[Events eventsNamed:[tempdict objectForKey:@"title"] description:[tempdict objectForKey:@"description"] date:t]];}
dataReady = YES;
[callback loadedDataSource:self];}
+ (Events*)eventsNamed:(NSString *)atitle description:(NSString *)adescription date:(NSDate *)aDate {
return [[[Events alloc] initWithName:atitle description:adescription date:aDate] autorelease]; }
打印我所有的数据都很好,但在这一行
[eventPHP addObject:[Events eventsNamed:[tempdict objectForKey:@"title"] description:[tempdict objectForKey:@"description"] date:t]];
有例外:
** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSDate 长度]:无法识别的选择器发送到实例 0x6149cb0”
【问题讨论】:
-
eventPHP 是什么类?是 NSArray 吗?
-
请在事件上发布 initWithName:atitle description:adescription date:aDate 方法
-
代码示例应该完整简洁。请提供minimal sample。当前示例包含无关代码。
-
Mike K : eventPHP 它是数组 [ NSMutableArray ] Dimitar - (id)initWithName:(NSString *)atitle description:(NSString *)description date:(NSDate *)aDate { if ((self = [超级初始化])) { 标题 = [标题副本];描述 = [描述副本];日期 = [aDate 保留]; } return self;} initWithName 有什么问题吗?