Xcode给出了错误:
函数不透明返回类型被推断为'Button',它根据自身定义不透明类型
在以下线路上:
@State var showingProfile = false // Could be also Binding or else
var profileButton: some View {
Button(action: { self.showingProfile.toggle() }) { // <- Error on this line
Image(systemName: "person.crop.circle")
.imageScale(.large)
.accessibility(label: Text("User Profile"))
.navigationBarItems(trailing: self.profileButton)
.padding() } } }发布于 2019-12-07 18:52:25
你想要做到这一点吗?
struct ProfileButton: View {
@State var showingProfile = false // Could be also Binding or else
var body: some View {
Button(action: {
self.showingProfile.toggle()
}) {
Text("blubb")
Image(systemName: "person.crop.circle")
.imageScale(.large)
.accessibility(label: Text("User Profile"))
.padding()
}
}
}
struct ContentView: View {
let profileButton = ProfileButton(showingProfile: true)
var body: some View {
NavigationView {
Text("aah")
.navigationBarTitle("Test")
.navigationBarItems(trailing: Image(systemName: "person.crop.circle"))
}
}
}https://stackoverflow.com/questions/59229011
复制相似问题