![](/img/trans.png)
[英]Reverse NSTimer for scheduledTimerWithTimeInterval in Objective-C
[英]Cannot make a slide image in objective-c of Xcode by UICollectionView and NSTimer
嗨,我将NS参数传递给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;
这是因为您要在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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.