嗨,当我将一个参数传递给scrollToItemAtIndexPath
,它总是被终止时,我遇到了NSTimer的问题。有人可以帮忙吗?
SlideCollectionViewCell *cell = [collectionImageSlideView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
cell.showImage.image = [UIImage imageNamed:[images objectAtIndex:indexPath.row]];
NSInteger rowIndex = indexPath.row;
NSInteger imageCount = self->images.count-1;
if(rowIndex<imageCount){
rowIndex = rowIndex+1;
}else{
rowIndex = 0;
}
scrollingTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0
target: self
selector:@selector(startTimer:)
userInfo: @(rowIndex) repeats:YES];
return cell;
答案 0 :(得分:0)
这是因为你要在NSIndexpath变量中传递一个NSInteger,你需要创建一个NSIndexpath然后将它传递给如下函数: -
cell.showImage.image = [UIImage imageNamed:[images objectAtIndex:indexPath.row]];
NSInteger rowIndex = indexPath.row;
NSInteger imageCount = self->images.count-1;
if(rowIndex<imageCount){
rowIndex = rowIndex+1;
}else{
rowIndex = 0;
}
NSIndexPath *indexToPass=[NSIndexPath indexPathForRow:rowIndex inSection:indexPath.section];
scrollingTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0
target: self
selector:@selector(startTimer:)
userInfo:indexToPass repeats:YES];
return cell;