HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 使用MultivaluedSection的奇怪行为?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
)

我已经使用Eureka一段时间了,太棒了!

最近我在使用MultivaluedSection,我编写了一个简单的测试项目:它简单地从tableView添加/删除人.

这里是代码,首先是模型:Person

struct Person:Equatable,CustomStringConvertible{
    var description: String{
        return "\(Name) \(id)"
    }

    static func ==(lhs: Person,rhs: Person) -> Bool {
        return lhs.id == rhs.id
    }

    var id:string
    var name:string

    init(name:string){
        self.id = UUID().uuidString
        self.name = name
    }
}

VC的下一个代码

class ViewController: FormViewController {

    var people:[Person] = []

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //hide delete button at row left
        tableView.isEdiTing = false
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let peopleSection = MultivaluedSection(multivaluedoptions:[.delete,.Reorder,.Insert],header:"people")

        peopleSection.tag = "people"
        peopleSection.multivaluedRowToInsertAt = {idx in
            let newRow = LabelRow(){row in
                let person = Person(name: "h\(idX)")
                row.value = person.description
                self.people.append(person)

                let deleteAction = SwipeAction(style: .destructive,title: "DEL"){action,row,completion in
                    completion?(true)
                }
                row.TrailingSwipe.actions = [deleteAction]
            }
            return newRow
        }

        peopleSection.addButtonProvider = {section in
            let addBtn = ButtonRow("add"){row in
                row.title = "new person"
            }
            return addBtn
        }

        form +++ peopleSection
    }
}

运行应用程序,如下图所示:

ios – 使用MultivaluedSection的奇怪行为?

有两个问题:

1:你可以看到我添加3个人然后按顺序删除它们,一切都很好!但是,当我再次添加一个人时,发生了一些错误:似乎该部分的标题被拉得很长.为什么???

2:当我向tableView添加一些人时,标题没有左对齐,为什么:

@L_675_15@

非常感谢!

解决方法

请更新代码,

peopleSection.multivaluedRowToInsertAt = {idx in
    return LabelRow() {
        let person = Person(name: "h\(idX)")
        $0.title = person.description
        self.people.append(person)
    }
}

它将为您提供以下输出,删除也将正常工作.

ios – 使用MultivaluedSection的奇怪行为?

大佬总结

以上是大佬教程为你收集整理的ios – 使用MultivaluedSection的奇怪行为?全部内容,希望文章能够帮你解决ios – 使用MultivaluedSection的奇怪行为?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。