ios - 如何将图像/数据从 iCarousel 传递到新的 View Controller

标签 ios swift icarousel

我在我的一个 View Controller 中设置了一个 iCarousel,我想简单地将用户点击的相同图像传递到下一个 View Controller 。这是我在 Carousel VC 上的 prepareForSegue 中的内容:

 var padIndex = [UIImage]()

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {



   let nextVC = segue.destination as! BlackViewController

   let indexPath = sender as! NSIndexPath

    nextVC.pad = self.images[indexPath.row]
}

然后在我的第二个 VC 中我有:

var pad = UIImage()

@IBOutlet weak var padImage: UIImageView!

 override func viewDidLoad() {
    super.viewDidLoad()

     padImage.image = pad
}

看起来很简单,但我一直收到错误消息:

Could not cast value of type 'SampleSequencer.ChooseViewController' (0x10213fe38) to 'NSIndexPath' (0x1025b8440).

提前十亿表示感谢!!

最佳答案

异常告诉您您进行了非法转换。错误在这里:

let indexPath = sender as! NSIndexPath

prepare(for:sender:)sender 参数说它可以是Any?,但实际上,它并不可怕有用,因为你不能确定它会是什么。您必须从 iCarouselDelegate 获取 IndexPath(如果它实现了 iCarouselDelegate,它可能是您自己的 View Controller ),使用委托(delegate)的 carousel(_:,didSelectItemAtIndex:) 方法。

关于ios - 如何将图像/数据从 iCarousel 传递到新的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50422241/

相关文章:

ios - 从 OpenGL 绘图创建 png UIImage

iphone - Flash中IOS开发中的default.png图片

ios - 展开/折叠在 Storyboard中工作正常但在 xib 中不工作

ios - tableView.hidden 破坏其他元素

iOS:对 iCarousel 中未选择 View 的约束

ios - iCarousel 中的分页

ios - 自定义 UITableViewCell,一个包含两个 subview 的 UIView,并且可以滚动

ios - 压缩build设置中缺少的 Png 文件

ios - UICollectionView 放大选择的单元格

ios6 - iCarousel 与 iOS 6.1 中具有标签栏 Controller 的应用程序集成