【问题标题】:Cannot make a slide image in objective-c of Xcode by UICollectionView and NSTimer无法通过 UICollectionView 和 NSTimer 在 Xcode 的objective-c 中制作幻灯片图像
【发布时间】:2018-11-24 21:38:32
【问题描述】:

嗨,当我将参数传递给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;

【问题讨论】:

    标签: ios objective-c uiscrollview uicollectionview nstimer


    【解决方案1】:

    这是因为您在 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;
    

    【讨论】:

    • 谢谢你的回答,它像老板一样工作。希望能和你保持联系
    • 当然你可以拥有我的Skype - @kuldeep1007tanwar :)
    猜你喜欢
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 2017-12-31
    • 2015-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多