【问题标题】:Extra argument in call inside Group View [duplicate]组视图内调用中的额外参数[重复]
【发布时间】:2021-09-05 20:49:11
【问题描述】:

我的女巫上有一个屏幕,只显示文本,但是当我尝试在我的组视图中添加超过 10 个视图时,我收到了这个错误。我试图用组视图包装 VStack,但没有任何改变

Extra argument in call

我的代码:

struct GoalTipsView: View {
    
    var body: some View {
        
        NavigationView {
            
            ScrollView {
                
                VStack(alignment: .leading) {
                    
                    Group {
                        
                        HStack(spacing: 5) {
                            Text("Using the")
                            Text("Smart").bold()
                            Text("format is important for")
                            Spacer()
                        }.padding(.leading, 7)
                        
                        HStack(spacing: 5) {
                            Text("structuring goals correctly and increases the")
                        }.padding(.leading, 7)
                        
                        HStack(spacing: 5) {
                            Text("chance of success").bold()
                        }.padding(.leading, 7)
                        .padding(.bottom, 35)
                        
                        HStack(spacing: 5) {
                            Text("SPECIFIC").bold().font(.system(size: 23))
                        }.padding(.leading, 10)
                        
                        HStack(spacing: 5) {
                            Text("(Goals that are simple, sensible, significant.) \n A specific goal allows you to focus on a clear and specific target. It can help you visualise the desired outcome and makes it easier to track your progress. Focusing the mind on the desired goals is important for success. Every word needs to be useful and necessary in the goal sentence.").padding(5)
                        }.padding(.leading, 7)
                        
                        HStack(spacing: 5) {
                            Text("MEASURABLE").bold().font(.system(size: 23))
                        }.padding(.leading, 10)
                        .padding(.top, 23)
                        
                        HStack(spacing: 5) {
                            Text("(goals that are meaningful, motivating.) \n If your goal isn't measurable, there will be no way to determine if it\'s achieved. Work out the criteria for measuring progress towards the achievement of the goal. \n When the goal is measured you, are much more likely to keep on track, reach milestones, and experience the achievement that is needed for continued effort required to reach the goal.").padding(5)
                        }.padding(.leading, 10)
                        
                        
                        HStack(spacing: 5) {
                            Text("To assist with making the goal measurable:").bold().font(.system(size: 18))
                        }.padding(.leading, 10)
                        .padding(.top, 20)
                        
                        
                        HStack(spacing: 5) {
                            Text("How will i know when it is accomplished? \n What exactly needs to happened to consider this goal achieved?").padding(5)
                            Spacer()
                        }
                        
                        
                        HStack(spacing: 5) {
                            Text("ASSIGNABLE/ACTION-ORIENTED").bold().font(.system(size: 23))
                        }.padding(.leading, 10)
                        .padding(.top, 23)
                        
                        
                        HStack(spacing: 5) {} // Extra argument in call
                        
                        
                    }
                    
                }.padding(.top, 10)
                
            }.navigationBarHidden(true)
            
        }
        
    }
}

struct GoalTipsView_Previews: PreviewProvider {
    static var previews: some View {
        GoalTipsView()
    }
}

【问题讨论】:

    标签: ios swift swiftui


    【解决方案1】:

    这是 SwiftUI 的限制:在任何容器内的同一级别上,您不能有超过 10 个视图。

    这是因为 SwftUI 是如何构建的。想象一下每个@ViewBuilder 函数都有这样的实现:

    func viewBuilder(_ argument1: some View)
    func viewBuilder(_ argument1: some View, _ argument2: some View)
    ...
    func viewBuilder(_ argument1: some View, _ argument2: some View, ..., _ argument10: some View)
    

    他们不得不在某个时候停下来,现在是 10 点。

    您可以将您的视图放在另一个Group 中:这是它的用途之一。您也可以将它们移动到@ViewBuilder func subgroup() -> some View {}

    struct GoalTipsView: View {
    
        var body: some View {
    
            NavigationView {
    
                ScrollView {
    
                    VStack(alignment: .leading) {
    
                        Group {
                            Group {
                                HStack(spacing: 5) {
                                    Text("Using the")
                                    Text("Smart").bold()
                                    Text("format is important for")
                                    Spacer()
                                }.padding(.leading, 7)
    
                                HStack(spacing: 5) {
                                    Text("structuring goals correctly and increases the")
                                }.padding(.leading, 7)
    
                                HStack(spacing: 5) {
                                    Text("chance of success").bold()
                                }.padding(.leading, 7)
                                    .padding(.bottom, 35)
    
                                HStack(spacing: 5) {
                                    Text("SPECIFIC").bold().font(.system(size: 23))
                                }.padding(.leading, 10)
    
                                HStack(spacing: 5) {
                                    Text("(Goals that are simple, sensible, significant.) \n A specific goal allows you to focus on a clear and specific target. It can help you visualise the desired outcome and makes it easier to track your progress. Focusing the mind on the desired goals is important for success. Every word needs to be useful and necessary in the goal sentence.")
                                        .padding(5)
                                }.padding(.leading, 7)
    
                                HStack(spacing: 5) {
                                    Text("MEASURABLE").bold().font(.system(size: 23))
                                }.padding(.leading, 10)
                                    .padding(.top, 23)
    
                                HStack(spacing: 5) {
                                    Text("(goals that are meaningful, motivating.) \n If your goal isn't measurable, there will be no way to determine if it\'s achieved. Work out the criteria for measuring progress towards the achievement of the goal. \n When the goal is measured you, are much more likely to keep on track, reach milestones, and experience the achievement that is needed for continued effort required to reach the goal.")
                                        .padding(5)
                                }.padding(.leading, 10)
    
                                HStack(spacing: 5) {
                                    Text("To assist with making the goal measurable:").bold().font(.system(size: 18))
                                }.padding(.leading, 10)
                                    .padding(.top, 20)
    
                                HStack(spacing: 5) {
                                    Text("How will i know when it is accomplished? \n What exactly needs to happened to consider this goal achieved?")
                                        .padding(5)
                                    Spacer()
                                }
    
                                HStack(spacing: 5) {
                                    Text("ASSIGNABLE/ACTION-ORIENTED").bold().font(.system(size: 23))
                                }.padding(.leading, 10)
                                    .padding(.top, 23)
                            }
    
    
                            HStack(spacing: 5) {} // Extra argument in call
    
    
                        }
    
                    }.padding(.top, 10)
    
                }.navigationBarHidden(true)
    
            }
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多