這是我的代碼:拋出異常[__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'
什麼類是eventPHP?它是一個NSArray? – 2011-12-25 22:42:40
請發送initWithName:atitle描述:adescription date:事件的日期方法 – 2011-12-25 22:44:04
代碼示例應該是完整和簡潔的。請提供[最小樣本](http://sscce.org/)。當前示例有無關的代碼。 – outis 2011-12-25 22:51:32