これはおそらく手遅れであることはわかっていますが、あなたが見つけた解決策よりもはるかに優れています. iOS は という名前のメソッドを提供しますtableView: editActionsForRowAtIndexPath indexPath:
。この方法では、基本的に独自の UITableViewRowActions を追加できます。これは、UIButtons を使用して UIView 全体を追加するよりもはるかに簡単 (かつクリーン) です。
アップルは次のように述べています。
テーブル行の 1 つにカスタム アクションを提供する場合は、このメソッドを使用します。ユーザーが行を横方向にスワイプすると、テーブル ビューは行のコンテンツを横に移動してアクションを表示します。アクション ボタンの 1 つをタップすると、アクション オブジェクトに格納されているハンドラ ブロックが実行されます。
このメソッドを実装しない場合、ユーザーが行をスワイプすると、テーブル ビューに標準のアクセサリ ボタンが表示されます。
必要に応じて、 Apple のドキュメントを自分で見ることができます。
例(スウィフト)
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let customAction = UITableViewRowAction(style: .Normal, title: "Your Custom Action", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) in
println("Do whatever it is you want to do when they press your custom action button")
})
editAction.backgroundColor = UIColor.greenColor()
let deleteAction = UITableViewRowAction(style: .Normal, title: "Delete", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) in
println("You can even implement a deletion action here")
})
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction, editAction]
}