2011-12-25 27 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

相關問題