Ios 多值分割的奇怪行为?

Ios 多值分割的奇怪行为?,ios,eureka-forms,Ios,Eureka Forms,) 我已经使用Eureka一段时间了,它太棒了 最近我在处理MultivaluedSection,我编写了一个简单的测试项目:从tableView添加/删除人员 下面是代码,第一个用于model:Person struct Person:Equatable,CustomStringConvertible{ var description: String{ return "\(name) \(id)" } static func ==(lhs: Perso

)

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

最近我在处理MultivaluedSection,我编写了一个简单的测试项目:从tableView添加/删除人员

下面是代码,第一个用于model: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个人,然后按顺序删除,一切都好!但当我再次添加person时,出现了一些错误:该部分的标题似乎被拖得很长。为什么

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


非常感谢

请更新代码

peopleSection.multivaluedRowToInsertAt = {idx in
    return LabelRow() {
        let person = Person(name: "h\(idx)")
        $0.title = person.description
        self.people.append(person)
    }
}
它将为您提供以下输出,delete也将正常工作


关于您的第一个问题:SwipeAction实际上并没有从表中删除该行。要使其正常工作,您可以按如下方式手动删除此行:

let deleteAction = SwipeAction(style: .destructive, title: "DEL") { action, row, completion in

    // Delete row:
    if let rowNum = row.indexPath?.row {
        row.section?.remove(at: rowNum)
    }

    completion?(true)
}
row.trailingSwipe.actions = [deleteAction]

请将SwipeAction的代码全部放在上面的代码中:deleteAction!您可以看到,除了调用完成?(true)之外,它是空的。使用未解析标识符“SwipeAction”错误是自Eureka 4.1.0以来Eureka中内置的SwipeAction。也许你必须更新pod并重新安装:1.pod repo update 2.pod install和我的第一个问题?