Swift-无法推断出通用参数'Label'

问题描述 投票:0回答:1

仅遵循了教程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()
                    })]

                )
            }

        }
    }




}
ios swift xcode swiftui
1个回答
0
投票

ActionSheet参数不正确,应为isPresented而不是item。顺便说一下,尝试将您的代码切成较小的代码块,以帮助Xcode推断闭包。

© www.soinside.com 2019 - 2024. All rights reserved.