いつもお世話になります。
UITableView
にセクションをインサートしているのですが、インサートされた直下のSectionHeader
に設定しているラベルの文字列のみ更新する方法はないでしょうか?
アニメーションの都合もあり、tableView.reloadData()
コールし辛いです。
tableView.reloadSections
を呼ぶとアニメーションが変になりますし、tableView.reloadRows
ではヘッダーは更新されないようです。
swift
1// generateSection 2 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 3 4 let headerView = testTableView.dequeueReusableHeaderFooterView(withIdentifier: "Section") as! SectionHeaderView 5 headerView.removeSectionBtn.tag = section 6 headerView.removeSectionBtn.isEnabled = section == 0 ? false: true 7 8 headerView.SectionHeaderViewDelegate = self 9 10 let labelStr = "Section:" + String(section + 1) 11 headerView.setValueToSection(LabelStr: labelStr) 12 13 return headerView 14 } 15
swift
1// セクションヘッダーを追加する処理 2 @IBAction func addSectionHeaderView(_ sender: UILongPressGestureRecognizer) { 3 if(sender.state == UIGestureRecognizer.State.began) { 4 } else if (sender.state == UIGestureRecognizer.State.ended) { 5 6 let point = sender.location(in: testTableView) 7 guard let indexPath = testTableView.indexPathForRow(at: point) else { return } 8 9 if !(indexPath.row == 0) { 10 // 配列操作 11 let targetArray = arrayOfArray[indexPath.section] 12 let firsrOfTargetArray = targetArray.prefix(indexPath.row) 13 let secondOfTargetArray = targetArray.dropFirst(indexPath.row) 14 arrayOfArray.remove(at: indexPath.section) 15 arrayOfArray.insert(firsrOfTargetArray.map{$0}, at: indexPath.section) 16 arrayOfArray.insert(secondOfTargetArray.map{$0}, at: indexPath.section + 1) 17 18 // 削除するインデックスパスの配列を作る 19 let deleteIndexes: [IndexPath] = 20 (indexPath.row ..< targetArray.count).map {[indexPath.section, $0]} 21 22 // tableView操作 23 testTableView.beginUpdates() 24 testTableView.deleteRows(at: deleteIndexes, with: insertFA) 25 testTableView.insertSections(IndexSet(integer: indexPath.section + 1), with: insertLA) 26 testTableView.endUpdates() 27 28 print("indexPathsForVisibleRows.count:",testTableView.indexPathsForVisibleRows?.count) 29 print("visibleCells.count:",testTableView.visibleCells.count) 30 /* 31 guard let visibleIndexes = testTableView.indexPathsForVisibleRows else { return } 32 // 画面上に見えている範囲のセルのみ更新 33 testTableView.reloadRows(at: visibleIndexes, with: .none) 34 */ 35 } 36 } 37 } 38 39 40
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/10/02 13:41 編集