繁体   English   中英

UICollectionView和NSTimer无法在Xcode的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM