也成为MPMediaPickerControllerDelega

也成为MPMediaPickerControllerDelega

本文介绍了迅速地,有没有办法让UIView类也成为MPMediaPickerControllerDelegate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用Swift开发音乐应用.这是我的第一个应用程序(不算几个教程的内容).我一直在看一些示例代码,包括Apple的addMusic示例,并且在将目标c代码转换为swift时遇到了以下问题:

I am currently trying to make a music app using swift. This is my first app (not counting a couple tutorial things). I've been looking at some sample code, including Apple's addMusic example, and I have had issues with the following translation of the objective c code into swift:

class ViewController: UIViewController <MPMediaPickerControllerDelegate> {

我收到错误消息无法专门化非通用类型'UIViewController'.是否有一种方法可以使我丢失,或者我需要定义一个单独的类作为我的选择器委托?

I get the error "Cannot specialize non-generic type 'UIViewController'. Is there a way to do this that I am missing or will I need to define a separate class to be my picker delegate?

我正在查看的addMusic代码为此处.

The addMusic code I was looking at is here.

推荐答案

与Objective-C不同,子类和委托的结构彼此相同,且周围没有<>".例如:

unlike in objective-c, the subclasses and delegates are structured the same as each other with none of the "<>" around them. For example:

class ViewController: UIViewController, MPMediaPickerControllerDelegate, UITableViewDelegate, CustomClassDelegate

您可以继续添加到列表中,尽管只有一个类可以是超类(其余的必须是委托或类似的类),因为一个类不能同时是两个不同父类的子类.

You can continually add to the list as you go along, though only one of them can be the superclass (the rest must be delegates or similar) as a class cannot be the subclass of two different parent classes at the same time.

希望有帮助.

这篇关于迅速地,有没有办法让UIView类也成为MPMediaPickerControllerDelegate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 11:08