In iOS 8, how to add Row Action Buttons to the left side of a UITableViewCell

妖精的绣舞 提交于 2019-12-18 08:48:28

问题


Apple shows these images on their product page for iOS 8. I am interested in adding buttons to the left side of a table row as shown in the first image. Is this a public API? Note that I am already aware of the delegate method for adding buttons to the right side. I've looked through the WWDC session videos and documentation to no avail.

Thanks in advance.

Pic: buttons on left

Pic: buttons on right


回答1:


You can use the tableview delegate method: leadingSwipeActionsConfigurationForRowAt

See Swipe Actions since iOS 11: Table Swipe Actions




回答2:


It's a public API to a point in iOS8, as explained in answers here Swipe to Delete and the "More" button (like in Mail app on iOS 7)

There are also several implementations already on Github, such as this one by MortimerGoro (part of the answer above).

If you want to do it yourself, you can use a custom UISCrollView or add subviews to your cell's contentView. Add gesture recognizers as appropriate to handle different swipe directions. Essentially you reposition the button subviews with negative values as the gesture progresses, which gives the appearance of uncovering static buttons. In reality, everything is moving, just in opposite directions.

Ray Wenderlich.com has a very in-depth tutorial for how to recreate the effect. It's also a right-sided button approach, but the concepts are identical - just swap the direction of the swipe gesture & where you place the button subviews.




回答3:


func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]{

    let ackAction:UITableViewRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Himanshu", handler: myFunction)
    ackAction.backgroundColor = UIColor.orangeColor()

    return [ackAction]
}

edit: fixed code indentation



来源:https://stackoverflow.com/questions/25939964/in-ios-8-how-to-add-row-action-buttons-to-the-left-side-of-a-uitableviewcell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!