简体   繁体   English

投放到自定义类的问题

[英]Issue casting to custom class

I am using these two libraries . 我正在使用两个

My goal here is to get a player into each cell of the carousel view. 我的目标是让玩家进入轮播视图的每个单元。 So far I have just been following the example in the iCarousel repo. 到目前为止,我只是遵循iCarousel库中的示例。

If you look at the example in the git repository, you will see that the cell is created and then referenced to. 如果查看git存储库中的示例,您将看到该单元已创建,然后被引用。

to reference the player in the reused view I am trying 在我尝试的重用视图中引用播放器

let player: Player
    if view == nil {
       player = Player()
       //Do stuff with player
    } else {
       player = view.viewWithTag(1) as! Player
    }

but I get the error: Cast from UIView to unrelated type 'Player' always fails 但是我得到了错误:从UIView投射到不相关的类型'Player'总是失败

any help is appreciated 任何帮助表示赞赏

The call to view.viewWithTag(1) returns a UIView but Player is a subclass of UIViewController which are not related, so you cannot cast from one to another. view.viewWithTag(1)的调用返回一个UIViewPlayerUIViewController的子类,它们不相关,因此您不能从一个类型转换为另一个。 You need UIView s for the carousel so you cannot use the Player class. 轮播需要UIView ,因此不能使用Player类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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