SwiftUI 抱怨在 navigationBarItems 中没有更多上下文,表达式类型不明确 [英] SwiftUI is complaining Type of expression is ambiguous without more context in navigationBarItems leading

查看:27
本文介绍了SwiftUI 抱怨在 navigationBarItems 中没有更多上下文,表达式类型不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在 navigationBarItems 中放置了一些视图,领先的属性.但是 Xcode 一直在我的第一个 Text 元素中抱怨没有更多上下文的表达式类型不明确":

I'm just placing some views in navigationBarItems, leading property. but Xcode keep complaining "Type of expression is ambiguous without more context" in my first Text element:

var body: some View {
    NavigationView {
        List {
            ForEach(people) {person in
                PersonView(person: person)
            }
        }.navigationBarItems(leading: VStack {
                HStack(spacing: 100) {
                    Text("Find People").font(.system(size: 30)).bold()
                    Text("Follow All").foregroundColor(Color(ColorUtils.hexStringToUIColor(hex: Constants.THEME.THEME_COLOR)))
                }
                HStack(spacing: 100) {
                     Text("Import from: ")
                     ForEach(socialIcons, id: \.self) {icon in
                         Image(icon).resizable().frame(width: 25, height: 25)
                     }
                }
            },
            trailing: nil
        )
    }
}

这就是我想要的

这是我的代码快照:

推荐答案

不要相信 Xcode:

Xcode 不是很聪明 告诉您 SwiftUI 中的真正问题是什么足够(还).不管你信不信,问题在于 trailing: nil.

Don't Trust Xcode:

Xcode is not very intelligent to tell you what is the real issue in SwiftUI enough (yet). So believing or not, the issue is with the trailing: nil.

你应该摆脱它!

那就是:

    .navigationBarItems(leading: VStack {
        HStack(spacing: 100) {
            Text("Find People").font(.system(size: 30)).bold()
            Text("Follow All").foregroundColor(Color(ColorUtils.hexStringToUIColor(hex: Constants.THEME.THEME_COLOR)))
        }
        HStack(spacing: 100) {
            Text("Import from: ")
            ForEach(socialIcons, id: \.self) {icon in
                Image(icon).resizable().frame(width: 25, height: 25)
            }
        }
    }) /* `trailing: nil` removed */

这篇关于SwiftUI 抱怨在 navigationBarItems 中没有更多上下文,表达式类型不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆