【问题标题】:Argument passed to call that takes no arguments in SwiftUI传递给在 SwiftUI 中不带参数的调用的参数
【发布时间】:2021-05-29 03:07:37
【问题描述】:

我正在尝试将ScrollView 添加到我的视图中,以便用户可以向下滚动,但是我收到错误“传递给不带参数的调用的参数”据我了解,当 10 个或更多元素出现在看看,但是我有不到 10 个。

struct FavoritesView: View {
    var body: some View {
        VStack{
            HStack(alignment: .center){
                VStack(alignment: .leading){
                    Text("Your Favorite Shots")
                        .font(.system(size: 29, weight: .bold))
                    
                    Text("125 Shots")
                        .font(.system(size: 12, weight: .regular))
                        .opacity(0.5)   
                }

                Image("profile")
                    .resizable()                    
 
            }.frame(width: UIScreen.screenWidth / 1.05, height: 100, alignment: .top)

            ScrollView{
            //ERROR IS HERE
                Text("test")
            }
            
        }
        
    }
    
}

【问题讨论】:

    标签: ios arrays swift


    【解决方案1】:

    SwiftUI 的错误消息有时会产生误导。问题其实出在这里:

    }.frame(width: UIScreen.screenWidth / 1.05, height: 100, alignment: .top)
    

    UIScreen 没有名为screenWidth 的属性。请改用UIScreen.main.bounds.width

    }.frame(width: UIScreen.main.bounds.width / 1.05, height: 100, alignment: .top)
    

    【讨论】:

    • 我为 UIScreen 创建了一个扩展,它将“screenWidth”反映到“UIScreen.main.bounds.width”
    • @user302975 嗯好吧。但这是唯一出现的错误。除了Text("test")ScrollView{} 里面还有其他代码吗?
    • 我在 ScrollView 中放入的任何代码都会导致错误。即使是空的 ScrollView 也会返回错误。
    • @user302975 在您的项目 (Command + Shift + F) 中搜索“ScrollView”一词。您可能已经使用相同的名称定义了自己的自定义结构/类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多