我已经使用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 }}
运行应用程序,如下图所示:
有两个问题:
1:你可以看到我添加3个人然后按顺序删除它们,一切都很好!但是,当我再次添加一个人时,发生了一些错误:似乎该部分的标题被拉得很长.为什么???
2:当我向tableVIEw添加一些人时,标题没有左对齐,为什么:
非常感谢!
解决方法 请更新代码,peopleSection.multivaluedRowToInsertAt = {IDx in return LabelRow() { let person = Person(name: "h\(IDx)") .Title = person.description self.people.append(person) }}
它将为您提供以下输出,删除也将正常工作.
总结以上是内存溢出为你收集整理的ios – 使用MultivaluedSection的奇怪行为?全部内容,希望文章能够帮你解决ios – 使用MultivaluedSection的奇怪行为?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)