仅遵循了教程here,但是我在NavigationLink行上遇到了错误Generic parameter 'Label' could not be inferred
。我尝试查找错误,但找不到任何解决方法。 Xcode提供了显式指定通用参数的修复程序,但是我不知道这意味着什么。它将我的代码更改为NavigationLink<Label: View, Destination: View>(destination)....
@State var imageData : Data = .init(capacity: 0)
@State var show = false
@State var imagepicker = false
@State var source : UIImagePickerController.SourceType = .photoLibrary
var body: some View {
NavigationView {
ZStack {
NavigationLink(destination: ImagePicker(show: $imagepicker, image: $imageData, source: source), isActive: $imagepicker) {
Text("")
}
VStack {
if imageData.count != 0 {
Image(uiImage:UIImage(data: self.imageData)!)
.resizable()
.clipShape(Circle())
.frame(width: 250, height: 250)
.overlay(Circle().stroke(Color.red, lineWidth: 5))
.foregroundColor(Color.purple)
} else {
Image(systemName: "person.fill")
.resizable()
.clipShape(Circle())
.frame(width: 250, height: 250)
.overlay(Circle().stroke(Color.red, lineWidth: 5))
.foregroundColor(Color.purple)
}
Button(action: {
self.show.toggle()
}){
Text("Take a photo!")
.frame(width: 150, height: 150, alignment: .center)
.background(Color.green)
}
}.actionSheet(item: $show) {
ActionSheet(title: Text("Take a photo or select from photo library"), message: Text(""), buttons:
[.default(Text("Photo Library "), action: {
self.source = .photoLibrary
self.imagepicker.toggle()
}), .default(Text("Camera"), action: {
self.source = .camera
self.imagepicker.toggle()
})]
)
}
}
}
}
ActionSheet
参数不正确,应为isPresented
而不是item
。顺便说一下,尝试将您的代码切成较小的代码块,以帮助Xcode推断闭包。
• 如何在 ios Swift 项目上安装 Parse SDK
• Typescript:从函数参数或函数中传递的泛型类型推断字符串文字值作为类型
• SwiftUI - IOS 16 - 如何在 MVVM 架构中使用新的 NavigationStack 和 NavigationPath 进行编程导航?
• 如何在 React-Admin 中使用 DataProvider 进行服务器端异步验证?
• 在领域 SwiftUI 异常中使用 Apple 登录:无法识别的选择器发送到实例
• 更新后网格不变
• 类型缩小是否可能影响 TypeScript 函数中的泛型类型参数?
• 为什么 Azure Devops API 告诉我必须为我的推送请求提供这些参数,而我已经这样做了?