設置標籤按鈕。
button1.tag = 0
button2.tag = 1
button3.tag = 2
button4.tag = 3
再加入目標
button1.addTarget(self, action: #selector(didTouchButton(_:)), for: .touchUpInside)
button2.addTarget(self, action: #selector(didTouchButton(_:)), for: .touchUpInside)
button3.addTarget(self, action: #selector(didTouchButton(_:)), for: .touchUpInside)
button4.addTarget(self, action: #selector(didTouchButton(_:)), for: .touchUpInside)
那麼當按鈕可以選擇檢查發件人標籤,並做部分操作
func didTouchButton(_ sender: UIButton) {
let section = sender.tag
//do operations in section
}
Here是插入和刪除在部分行的例子基於部分指數。在Swift3中,您應該基於以下方法:
func insertRows(at: [IndexPath], with: UITableViewRowAnimation)
func deleteRows(at: [IndexPath], with: UITableViewRowAnimation)