简体   繁体   English

当细分市场发生变化时,如何在 Eureka 中更新我的列表?

[英]How can I update my list in Eureka when the segment is changing?

I made a form with a checkrow list and two segments where the user can either choose to select all items in the list or none.我制作了一个带有检查行列表和两个部分的表单,用户可以选择选择列表中的所有项目或不选择任何项目。

 private func setupForm() -> Void {
        
        guard let inheritorList = getInheritorList() else {
            return
        }

        
        form +++ Section()
            
            <<< LabelRow() { row in
                row.title = "Choose between multiple inheritors"
            }
            
            <<< SegmentedRow<Int>("segments") { row in
                row.options = [1,2]
                row.displayValueFor = { idx in
                    if idx == 1 {
                        return "All"
                    } else {
                        return "None"
                    }
                }
            }
            .onChange({ row in
                if row.value! == 1 {
                    //All checkboxes should be selected
                    self.inheritorFilterMode = .filterAll
                } else {
                    //All checkboxes should be deselected
                    self.inheritorFilterMode = .filterNone
                }
            })
        
        for inheritor in inheritorList {
                    form.last! <<< CheckRow("inheritors") { listRow in
                        listRow.title = inheritor.name
                        listRow.value = nil
                    }
                    .onChange({ row in
                        if row.value! {
                            self.inheritorsArray.insert(row.tag!)
                        } else {
                            self.inheritorsArray.remove(row.tag!)
                        }
                        
                    })
        }
    }
    

This creates a list with the above specified inheritors list and two segments.这将创建一个具有上述指定继承者列表和两个段的列表。 My problem is that I don't know how to obtain the values of the segmented row.我的问题是我不知道如何获取分段行的值。

I tried to create an enum and change the filter mode depending on the value in the onChange of my segmented row method.我尝试创建一个枚举并根据我的分段行方法的onChange中的值更改过滤器模式。 I would then later on in the onChange of my check row list check which mode is active but this didn't work.然后我稍后会在我的检查行列表的onChange中检查哪个模式处于活动状态,但这不起作用。

enum InheritorFilterMode {
    case filterAll, filterNone
}
...

var inheritorFilterMode: InheritorFilterMode = .filterAll

I also tried to obtain the value of the segments by getting the tag:我还尝试通过获取标签来获取段的值:

let segmentedRow: SegmentedRow<Int>! = self.form.rowBy(tag: "segments")

but this approach didn't work as well.但这种方法并不奏效。

Any suggestions on how to update the check boxes when the segment changes?关于如何在分段更改时更新复选框的任何建议?

I'm not quite sure if i understood the question.我不太确定我是否理解这个问题。 But I ll try to answer it.但我会尽力回答。

The checkmark itself is just a accessory type which changes the value of the row (check the repo for reference:复选标记本身只是一个附件类型,它改变了行的值(检查repo以供参考:

 accessoryType = row.value == true ? .checkmark : .none

So instead of filtering the results (which shouldn't work the way you did it) you should loop all rows in your form.因此,与其过滤结果(这不应该像您那样工作),您应该循环表单中的所有行。 There is a method form.allRows() which allows you to loop over all rows in your form and then you only need to check which segment - in your case "All" or "None" - is selected:有一个方法form.allRows()允许您遍历表单中的所有行,然后您只需要检查哪个段 - 在您的情况下是“全部”或“无” - 被选中:

So in the onChange block of your SegmentedRow you could do something like:因此,在SegmentedRowonChange块中,您可以执行以下操作:

.onChange({ segmentedRow in
   for row in self.form.allRows {
      if row is CheckRow {
        if segmentedRow.value == "All" {
           row.baseValue = true
        } else if segmentedRow.value == "None" {
            row.baseValue = false
          }
          // don't forget to call update cell - otherwise the cell won't update
          row.updateCell()
      }
   }
})

Also: Instead of using an Interger based row type you could just use a String :另外:您可以只使用String ,而不是使用基于Interger的行类型:

<<< SegmentedRow<String>("yourTagHere") { (segment) in 
    segment.options = ["All","None"]
...

I didn´t test it myself but it should do the trick.我没有自己测试它,但它应该可以解决问题。 It took me 10 minutes to read through the Eureka docs on GitHub.我花了 10 分钟阅读了 GitHub 上的Eureka文档。 Might be worth a try ;)也许值得尝试一下 ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我的列表为空时如何显示图像或文本? - How can I display an image or text when my List is empty? 如何在自定义尤里卡行中验证诸如textfield之类的对象? - How can I validate an object like textfield in a custom Eureka row? 在Swift 2中重新加载数据时,如何保持表格格式不变? - How can I keep the formatting of my table from changing when reloading the data in Swift 2? 单击搜索时如何更新tableView的框架并隐藏细分控件 - How to update frame of tableView and hide segment control when search is clicked 进入后台模式时,如何在应用中更新位置管理器和计时器? - How can i update location manager and a timer in my app when it goes to background mode? 如何从应用委托打开我的段 controller 的段索引? - How do I open the segment index of my segment controller from app delegate? 时间(以小时为单位)更改时如何更新我的应用程序用户界面 - How can I update my app UI when time( in hours) change 如何防止Xcode改变按钮的颜色? - How can I prevent Xcode from changing the color of my buttons? 如何在不更改 UI 的情况下添加 NavigationLink? - How can I add a NavigationLink without changing my UI? 如何让我的段UISegmentedControl响应? - How do I get my segment UISegmentedControl to respond?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM