Iphone “获取异常”;索引0超出空数组“的界限?”;?
我通过date pickerview从用户处获取开始日期和结束日期。当用户以速度滚动pickerview时,它会在那里崩溃,并给出此异常。那么解决办法是什么呢 [ @deepak和@Grady Player谈论的方法是:Iphone “获取异常”;索引0超出空数组“的界限?”;?,iphone,exception,nsmutablearray,uidatepicker,Iphone,Exception,Nsmutablearray,Uidatepicker,我通过date pickerview从用户处获取开始日期和结束日期。当用户以速度滚动pickerview时,它会在那里崩溃,并给出此异常。那么解决办法是什么呢 [ @deepak和@Grady Player谈论的方法是: -(void)getGraphicalData{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //[NSThread sleepForTimeInterval:1]; self
-(void)getGraphicalData{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//[NSThread sleepForTimeInterval:1];
self.friendBL = [[FriendBL alloc] init];
self.result = [self.friendBL getGraphicalData1:txtStartTime.text andTodate:txtEndTime.text];
if ([self.result isKindOfClass:[NSString class]]) {
UIAlertView * friendListAlertView = [[UIAlertView alloc] initWithTitle:@"Friend List" message:(NSString*) self.result delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[friendListAlertView show];
[friendListAlertView release];
}
else {
self.reportList = (NSMutableArray*) self.result;
NSLog(@"%d",[reportList count]);
}
[pool release];
}
选择日期后,我点击按钮说“完成”,这是代码
-(IBAction)doneBtn{
[dateView setHidden:YES];
NSLog(@"%@",[dateTimePicker date]);
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateStyle:NSDateFormatterBehaviorDefault];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
dateFormat.locale = locale;
if (tag) {
txtEndTime.text=[dateFormat stringFromDate:[dateTimePicker date]];
if (![self compareDates]) {
txtStartTime.text=@"";
txtEndTime.text=@"";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Date is not in valid" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
else {
txtStartTime.text=[dateFormat stringFromDate:[dateTimePicker date]];
}
NSLog(@"%@",[dateFormat stringFromDate:[dateTimePicker date]]);
}
但是,如果我缓慢地选择日期,它不会崩溃。您有一个数组,其中没有任何对象,您正在尝试访问第一个对象。如果您向我们显示代码,我们可以更具体。在上述函数中,您没有释放对象FriendBL。您如何存储您的属性?保留、分配或复制 可能是自动释放池有问题。该函数是否在主线程上调用
如果您能给我们提供更多信息,它可能会很有用。因为您不是通过线程调用该方法,所以不必使用自动释放池。您可以尝试以下代码吗
-(void)getGraphicalData{
self.friendBL = [[[FriendBL alloc] init] autorelease];
self.result = [self.friendBL getGraphicalData1:txtStartTime.text andTodate:txtEndTime.text];
if ([self.result isKindOfClass:[NSString class]]) {
UIAlertView * friendListAlertView = [[UIAlertView alloc] initWithTitle:@"Friend List" message:(NSString*) self.result delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[friendListAlertView show];
[friendListAlertView release];
}else {
self.reportList = (NSMutableArray*) self.result;
NSLog(@"%d",[reportList count]);
}
}
这是我最后一次尝试帮助:-(你能添加
S7GraphView
的drawRect:
方法吗?它来自S7GraphView而不是picker视图,你一定是在向它传递一些垃圾数据。@Deepak,这是谷歌代码上托管的东西,@Grady Player,不知道。看起来数据源方法有问题。@Mashadi,你是如何实现的数据源方法?你已经发布了我的方法,我使用的是谷歌的s7graphview代码。当我缓慢选择日期时,它不会崩溃,但如果我快速触摸它,它就会崩溃。我添加了更多的代码。我真的很惊讶它在快速滚动时会崩溃为什么不在慢速滚动上?我认为问题主要在于功能getGraphicalData。请给我self.friendBL和self.result属性的详细信息。同时如何调用函数getGraphicalData。能否使用[NSThread isMainThread]检查是否在主线程中调用该函数。当您在快速循环中使用自动释放池时,可能会产生一些不寻常的错误。我真的希望我能帮助您更多。谢谢您的帮助。我正在以这种方式调用方法}-(iAction)GraphicalBtc单击{if([txtStartTime.text length]>0&[txtEndTime.text length]>0){[self getGraphicalData];}GraphicalVC*GraphicalView=[[GraphicalVC alloc]initFromGraphical:reportList];[[self-navigationController]pushViewController:graphView animated:YES];}我对两者都使用属性retain,但我认为我应该在这里使用NSThread,而不是直接调用方法。
-(void)getGraphicalData{
self.friendBL = [[[FriendBL alloc] init] autorelease];
self.result = [self.friendBL getGraphicalData1:txtStartTime.text andTodate:txtEndTime.text];
if ([self.result isKindOfClass:[NSString class]]) {
UIAlertView * friendListAlertView = [[UIAlertView alloc] initWithTitle:@"Friend List" message:(NSString*) self.result delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[friendListAlertView show];
[friendListAlertView release];
}else {
self.reportList = (NSMutableArray*) self.result;
NSLog(@"%d",[reportList count]);
}
}