0

我正在尝试做一个 SegmentedRow。在每个部分中,都有 TextRows。这些 TextRows 在数量上是动态的。我试过了:

 +++ Section()
            <<< SegmentedRow<String>("segments"){
                $0.options = ["Assets", "Notes", "Photos"]
                $0.value = "Assets"
            }
            +++ Section(){
                $0.tag = "assets_s"
                $0.hidden = "$segments != 'Assets'" // .Predicate(NSPredicate(format: "$segments != 'Sport'"))
            }
            for t in myarray{
                <<< TextRow(){
                $0.title = "Which is your favourite soccer player?"
            }

            }

我尝试将 for 循环放在那里,但在随后的行中出现错误。

4

1 回答 1

2

我认为你需要的是这样的东西,这就是它的样子

在此处输入图像描述

class ViewController2: FormViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let assets = [String](arrayLiteral: "asset1","asset2","asset3")
        let notes = [String](arrayLiteral: "note1","note2","note3")
        let photos = [String](arrayLiteral: "photo1","photo2","photo3")
        // Do any additional setup after loading the view.

        form  +++ Section()
            <<< SegmentedRow<String>("segments"){
                $0.options = ["Assets", "Notes", "Photos"]
                $0.value = "Assets"
                }.onChange({ (segmented) in
                    if(segmented.value == "Assets")
                    {
                        segmented.section!.removeLast(segmented.section!.count - 1)

                        for value in assets
                        {
                            segmented.section! <<< TextRow(){
                                $0.title = value
                            }
                        }
                    }
                     if(segmented.value == "Notes")
                    {
                        segmented.section!.removeLast(segmented.section!.count - 1)

                        for value in notes
                        {
                            segmented.section! <<< ButtonRow(){
                                $0.title = value
                            }
                        }
                    }

                    if(segmented.value == "Photos")
                    {
                        segmented.section!.removeLast(segmented.section!.count - 1)

                        for value in photos
                        {
                            segmented.section! <<< TextRow(){
                                $0.title = value
                            }
                        }
                    }
                })

    }

}

我希望这可以帮助你

于 2016-06-28T16:21:20.623 回答