英文:
Does not conform to protocol 'UIViewControllerRepresentable'
问题
I'm completing the online apple Xcode Tutorial. At the UIKit tutorial portion, I'm repeatedly getting the same error:
"Type 'PageViewController
That portion of the tutorial is a few lines which are copied and pasted:
struct PageViewController<Page: View>: UIViewControllerRepresentable {
var pages: [Page]
}
How can I address this does not conform to protocol?
There are a few Does not conform to protocol errors posts online, each seemingly addressing the same error differently. Clicking fix the error adds this line to the file:
"typealias UIViewControllerType = <#type#>"
Which doesn't address the issue since the same error occurs.
英文:
I'm completing the online apple Xcode Tutorial. At the UIKit tutorial portion, I'm repeatedly getting the same error:
"Type 'PageViewController<Page>' does not conform to protocol 'UIViewControllerRepresentable'"
That portion of the tutorial is a few lines which are copied and pasted:
struct PageViewController<Page: View>: UIViewControllerRepresentable {
var pages: [Page]
}
How can I address this does not conform to protocol.
There are a few Does not conform to protocol errors posts online, each seemingly addressing the same error differently. Clicking fix the error adds this line to the file:
"typealias UIViewControllerType = <#type#>"
Which doesn't address the issue since the same error occurs.
答案1
得分: 1
你应该也要实现存根,就像这样:
struct PageViewController<Page: View>: UIViewControllerRepresentable {
typealias UIViewControllerType = UIViewController // <- 选择正确的控制器
func makeUIViewController(context: Context) -> UIViewControllerType {
// 根据需要实现
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
// 根据需要实现
}
var pages: [Page]
}
英文:
You should implement the stubs too, like:
struct PageViewController<Page: View>: UIViewControllerRepresentable {
typealias UIViewControllerType = UIViewController // <- Choose the correct controller
func makeUIViewController(context: Context) -> UIViewControllerType {
// Implement As needed
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
// Implement As needed
}
var pages: [Page]
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论