私はTableViewのカスタムUITableViewHeaderFooterViewを使用しています。私は、私が働いているセクションに隠れて行を表示するように実装しようとしていました。セクションヘッダーにボタン(>)を追加して、セクションが展開/折りたたまれているときに回転させることにしました。すべてのTableViewヘッダーのボタンに影響するアクション
ボタンをクリックすると表示される問題が発生します。 rotateCollapseButton()
関数が呼び出されると、クリックされたセクションヘッダーだけでなく、すべてのセクションヘッダーの(>)ボタンが回転します。時にはクリックされたボタンを除外したり、クリックしたボタンをクリックしても、別のボタンに影響を及ぼします。 正しいボタンだけが回転するようにするにはどうすればよいですか?
これは私が作成したカスタムヘッダーのコードです。
var rotated:Bool = false
var section:Int?
weak var delegate:MessageGroupHeaderDelegate?
@IBAction func expandCollapseButtonClicked(_ sender: Any) {
rotateCollapseButton(sender as! UIButton)
delegate?.didPressExpandCollapseButton(atSection : self.section!)
}
func rotateCollapseButton(_ button:UIButton) {
UIView.animate(withDuration: 0.5) {() -> Void in
var rotationAngle:CGFloat = CGFloat(M_PI_2)
if self.rotated {
rotationAngle = CGFloat(0)
}
button.transform = CGAffineTransform(rotationAngle : rotationAngle)
self.rotated = !self.rotated
}
}
EDIT:ヘッダが初期化されたコード...
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
// Dequeue with the reuse identifier
let cell = self.massMessageGroupsTableView.dequeueReusableHeaderFooterView(withIdentifier: "MessageGroupTableViewHeader")
let header = cell as! MessageGroupTableViewHeader
header.groupNameLabel.text = messageGroupsMap[section]?.messageGroup.name
header.section = section
header.setComposeButtonImage()
header.delegate = self
return cell
}
ありがとうございました!あなたのヘッダーの設定で
は、あなたはまた、あなたがセクションヘッダーを使用する方法のコードを貼り付けることはできますか?なぜなら、同じオブジェクトを使用しているとすれば、おそらくそのすべてが回転しているからです。 – unkgd
私は上記の編集を追加しました。それはあなたが指していたものですか? –
はい、すべてのセクションが画面に表示されますか?スクロールした後に矢印が回転しているのが見えますか? – unkgd