iOS 9 的 可以通过下面的代码拿到,self 是 UITableViewCell,但是9以下就不行了,而且这么拿 也不靠谱,有大神知道有什么更好的办法能过拿到这个按钮对象吗?
for (UIView *subView in self.subviews) {
if ([NSStringFromClass([subView class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
UIView *view = ((UIView *)[subView.subviews firstObject]);
}
}
怪我咯2017-04-17 16:41:12
Traversing subviews may not necessarily get the view you want, because sometimes, what you see is not necessarily a view, it may be a layer, or it may be just a small area drawn in the view.
If you want to get this view, all you can think of is customizing its text or style, and adding some touch events.
It is easy to modify the text and background color and add clicks. If you want to deeply customize this view, it may be better to implement one yourself.
Why don’t you tell me what you want to do after you get this? Maybe we can change our thinking.
Customized "Edit" and "Delete" button implementationtableView
的一个delegate
:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
// 编辑
let editAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "编辑") {
[unowned self](_, _) -> Void in
if let vc = self.pushViewController("TUAddSessionViewController") as? TUAddSessionViewController {
vc.session = TUCache.shared.sessionItems[indexPath.row]
vc.editMode = true
}
}
// 设置按钮背景色
editAction.backgroundColor = self.navigationController?.navigationBar.tintColor
// 删除
let delAction = UITableViewRowAction(style: UITableViewRowActionStyle.Destructive, title: "删除") {
(_, _) -> Void in
TUCache.shared.sessionItems.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
}
return [delAction, editAction]
}
黄舟2017-04-17 16:41:12
You probably want to modify the text on the button, then you can call the following API:
func tableView(tableView: UITableView!, editActionsForRowAtIndexPath indexPath: NSIndexPath!) -> [AnyObject]!
It allows you to customize multiple return buttons, and you can set a red button and multiple gray buttons.
You can refer to the following links:
http://www.cnblogs.com/scaptain/p/3950123.html
http://blog.csdn.net/lcl130/article/details/42131821