2011-12-25 49 views
0

这是我的代码:抛出异常[__NSDate长]:无法识别选择

- (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'

+0

什么类是eventPHP?它是一个NSArray? – 2011-12-25 22:42:40

+1

请发送initWithName:atitle描述:adescription date:事件的日期方法 – 2011-12-25 22:44:04

+0

代码示例应该是完整和简洁的。请提供[最小样本](http://sscce.org/)。当前示例有无关的代码。 – outis 2011-12-25 22:51:32

回答

1

你要发送的length消息给NSDate对象,但NSDate对象不了解length消息。您没有向我们展示发送该消息的代码。

如果设置objc_exception_throw断点时,Xcode会在调试程序停止您的应用程序发生异常时,这样你就可以清楚地看到在发送length消息哪里。

+0

雅我使用NSLog在initWhithName行中返回自我有例外 – 2011-12-26 16:49:26

相关问题