繁体   English   中英

在tableView数据值Swift顶部添加或附加带有行的部分

[英]Add or Append section with rows on top of tableView data values Swift

我在UITableView创建了一个带有部分和行的 DataList。 另外,我已经为add & delete功能实现了委托功能。 实际上我需要添加或附加新的section和选定的row值。 我的第一个模型是PickListData ,然后是从Item -> pickList检索的其他部分值。

模型层次结构: PickListData -> let items: [Item]? -> var pickList: [SectionList]? -> textField

我实现了func didAddnewRow(_ sender: UIButton)但它在该部分中添加了行,我需要在顶部添加名为Selected新部分。

  • 问题是怎样把Section选择的,从下面部分选定行。

我想实现的当前和实际附加的图像。

在向该部分添加行之前忘记添加新部分。 插入“Selected”部分后,“A. Items”部分将下移。

func numberOfSections(in tableView: UITableView) -> Int {
        return AppData?.pickList?.count ?? 0
    }



 func sectionIndexTitles(for tableView: UITableView) -> [String]? {

  return [“Selected", “A. Items"]
}




 func didAddnewRow(_ sender: UIButton) {
    if let cell = sender.superview?.superview as? DictionaryTableViewCell,
        let indexPath = self.tableView.indexPath(for: cell) {

        if let selectedItem = AppData?.pickList?[indexPath.section].items?[indexPath.row] {

            let insertIndexPath = IndexPath(item: AppData?.pickList?[0].items?.count ?? 0, section: 0)


    if !AppData?.pickList.contains(where: {$0.title == “Selected" }) {


   AppData?.pickList.append(SectionList(title: “Selected”, items: selectedItem))

   tableView.insertSections(IndexSet([selectedItem]), with: .automatic)

    } else {

      AppData?.pickList?[0].items?.append(selectedItem)
  }


            cell.btnAdd.isHidden = true
            cell.btnDelete.isHidden = false
            tableView.beginUpdates()

            tableView.insertRows(at: [insertIndexPath], with: .automatic)
            tableView.endUpdates()

        }
    }
}

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM