Ios 滚动uitableview时,不会使用sdwebImage加载图像
我正在做一项作业,我需要展示图片(即电影海报)在每个单元格中的uitableview上。我使用JSON解析获取图像的URL数组。我尝试在uitableview单元格上显示。但对于前60部电影,它与图像一起正确显示,但当我向下滚动时,它会给我一个异常。我使用Ios 滚动uitableview时,不会使用sdwebImage加载图像,ios,objective-c,uitableview,sdwebimage,Ios,Objective C,Uitableview,Sdwebimage,我正在做一项作业,我需要展示图片(即电影海报)在每个单元格中的uitableview上。我使用JSON解析获取图像的URL数组。我尝试在uitableview单元格上显示。但对于前60部电影,它与图像一起正确显示,但当我向下滚动时,它会给我一个异常。我使用SDWebImage框架,如下所示。我已导入#导入 这就是方法([self-loadData:pageNumber]),其中我为填充数组的键posterpath获取JSON值。它给出了如下例外情况: *** Terminating app du
SDWebImage
框架,如下所示。我已导入#导入
这就是方法([self-loadData:pageNumber]
),其中我为填充数组的键posterpath获取JSON值。它给出了如下例外情况:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x01aa65e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018298b6 objc_exception_throw + 44
2 CoreFoundation 0x01a58bcc -[__NSArrayM insertObject:atIndex:] + 844
3 CoreFoundation 0x01a58870 -[__NSArrayM addObject:] + 64
4 customizedCellTable 0x000032e5 -[tableViewClass loadData:] + 3029
5 customizedCellTable 0x00004643 -[tableViewClass scrollViewDidScroll:] + 467
6 UIKit 0x0062395b -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 62
7 UIKit 0x0060dc43 -[UIScrollView setContentOffset:] + 734
8 UIKit 0x0067f1d1 -[UITableView setContentOffset:] + 314
9 UIKit 0x0061ead2 -[UIScrollView _smoothScrollWithUpdateTime:] + 4009
10 UIKit 0x0061eda9 -[UIScrollView _smoothScrollDisplayLink:] + 222
11 QuartzCore 0x03b5db8a _ZN2CA7Display15DisplayLinkItem8dispatchEv + 48
12 QuartzCore 0x03b5da46 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 310
13 QuartzCore 0x03b5df6b _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 123
14 CoreFoundation 0x01a64bd6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
15 CoreFoundation 0x01a645bd __CFRunLoopDoTimer + 1181
16 CoreFoundation 0x01a4c628 __CFRunLoopRun + 1816
17 CoreFoundation 0x01a4bac3 CFRunLoopRunSpecific + 467
18 CoreFoundation 0x01a4b8db CFRunLoopRunInMode + 123
19 GraphicsServices 0x039fb9e2 GSEventRunModal + 192
20 GraphicsServices 0x039fb809 GSEventRun + 104
21 UIKit 0x00597d3b UIApplicationMain + 1225
22 customizedCellTable 0x00005fdd main + 141
23 libdyld.dylib 0x023c4725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我是iphone开发新手。提前谢谢。让我指出,您不应该在CellForRowatineXpath重新加载表-[tableview reload]触发调用一系列tableview委托方法,包括CellForRowatineXpath(对于表中的每一行执行一次,如果有100行,则执行100次),在该位置对调用进行编码将导致循环,[这可能是您的例外,尽管这似乎是一个非常常见的错误,即苹果可能为此类错误编写了处理程序]
我发现您的scrollViewdidscroll没有任何问题,因为它只是收集数据而不做任何其他操作,并且您的[loaddata Pagenumber]没有显示。您的问题可能在其他地方,请参阅堆栈跟踪。您的错误说明了问题所在
***-[\uu NSArrayM insertObject:atIndex:]:对象不能为零
它紧跟在scrollViewDidScroll
之后,然后loadData
,然后进入内部(向后读取跟踪,即向上读取跟踪)。
因此,在该方法中查找insertObject
,在某一点上,您传递的第一个参数是nil。由于您没有发布该代码,这就是我能提供的帮助。如果需要更多帮助,请返回
Z
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x01aa65e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018298b6 objc_exception_throw + 44
2 CoreFoundation 0x01a58bcc -[__NSArrayM insertObject:atIndex:] + 844
3 CoreFoundation 0x01a58870 -[__NSArrayM addObject:] + 64
4 customizedCellTable 0x000032e5 -[tableViewClass loadData:] + 3029
5 customizedCellTable 0x00004643 -[tableViewClass scrollViewDidScroll:] + 467
6 UIKit 0x0062395b -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 62
7 UIKit 0x0060dc43 -[UIScrollView setContentOffset:] + 734
8 UIKit 0x0067f1d1 -[UITableView setContentOffset:] + 314
9 UIKit 0x0061ead2 -[UIScrollView _smoothScrollWithUpdateTime:] + 4009
10 UIKit 0x0061eda9 -[UIScrollView _smoothScrollDisplayLink:] + 222
11 QuartzCore 0x03b5db8a _ZN2CA7Display15DisplayLinkItem8dispatchEv + 48
12 QuartzCore 0x03b5da46 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 310
13 QuartzCore 0x03b5df6b _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 123
14 CoreFoundation 0x01a64bd6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
15 CoreFoundation 0x01a645bd __CFRunLoopDoTimer + 1181
16 CoreFoundation 0x01a4c628 __CFRunLoopRun + 1816
17 CoreFoundation 0x01a4bac3 CFRunLoopRunSpecific + 467
18 CoreFoundation 0x01a4b8db CFRunLoopRunInMode + 123
19 GraphicsServices 0x039fb9e2 GSEventRunModal + 192
20 GraphicsServices 0x039fb809 GSEventRun + 104
21 UIKit 0x00597d3b UIApplicationMain + 1225
22 customizedCellTable 0x00005fdd main + 141
23 libdyld.dylib 0x023c4725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
__block UIActivityIndicatorView *activityIndicator;
__weak UIImageView *weakImageView = yourImageView;
[yourImageView sd_setImageWithURL:"your image url here..."
placeholderImage:[UIImage imageNamed:@"placeholder"]
options:SDWebImageProgressiveDownload
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
if (!activityIndicator) {
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
activityIndicator.center = weakImageView.center;
[activityIndicator startAnimating];
}
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}];