抛出异常[__NSDate length]:无法识别的选择器

时间:2011-12-25 22:26:30

标签: iphone xcode 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 length]:无法识别的选择器发送到实例0x6149cb0'

1 个答案:

答案 0 :(得分:1)

您正在向length对象发送NSDate消息,但NSDate个对象无法理解length消息。您没有向我们展示发送该消息的代码。

如果在objc_exception_throw上设置断点,Xcode会在发生异常时在调试器中停止您的应用,这样您就可以确切地看到length消息的发送位置。