首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >函数不透明返回类型被推断为.,它根据自身定义不透明类型。

函数不透明返回类型被推断为.,它根据自身定义不透明类型。
EN

Stack Overflow用户
提问于 2019-12-07 18:24:04
回答 1查看 743关注 0票数 6

Xcode给出了错误:

函数不透明返回类型被推断为'Button',它根据自身定义不透明类型

在以下线路上:

代码语言:javascript
复制
@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() } } }
EN

回答 1

Stack Overflow用户

发布于 2019-12-07 18:52:25

你想要做到这一点吗?

代码语言:javascript
复制
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"))
        }

    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59229011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档