UITableView 使用一行作为 segue
UITableView Using a row as a segue
所以我一直在尝试让任何行都像下一个 class 的 segue 一样,有点像在添加 [=10= 之后向左滑动可以删除该行的方式]
但我不想删除它,而是希望它显示另一个 class。如果有人可以提供帮助,那将是非常感谢
如果我对问题的理解是正确的,您希望用户在单元格上向左滑动,这会触发 segue 吗?
如果是这种情况,您可以尝试在 UITableViewDataSource class.[=12= 的 cellForRow
方法中使用 addGestureRecognizer
方法将 UISwipeGestureRecognizer 添加到单元格]
希望对您有所帮助!
您可以添加 swiprgesturerecognizer
类似
class MyViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
var recognizer = UISwipeGestureRecognizer(target: self, action: "didSwipe")
self.tableView.addGestureRecognizer(recognizer)
}
func didSwipe(recognizer: UIGestureRecognizer) {
if recognizer.state == UIGestureRecognizerState.Ended {
let swipeLocation = recognizer.locationInView(self.tableView)
if let swipedIndexPath = tableView.indexPathForRowAtPoint(swipeLocation) {
if let swipedCell = self.tableView.cellForRowAtIndexPath(swipedIndexPath) {
// Swipe happened. Do stuff!
}
}
}
}
}
这是一个示例,请根据需要进行管理。您可以添加滑动手势的 direction
属性 来处理特定方向的滑动,例如 UISwipeGestureRecognizerDirection.Left
或 Right
.
您可以参考。
希望这会有所帮助:)
所以我一直在尝试让任何行都像下一个 class 的 segue 一样,有点像在添加 [=10= 之后向左滑动可以删除该行的方式]
但我不想删除它,而是希望它显示另一个 class。如果有人可以提供帮助,那将是非常感谢
如果我对问题的理解是正确的,您希望用户在单元格上向左滑动,这会触发 segue 吗?
如果是这种情况,您可以尝试在 UITableViewDataSource class.[=12= 的 cellForRow
方法中使用 addGestureRecognizer
方法将 UISwipeGestureRecognizer 添加到单元格]
希望对您有所帮助!
您可以添加 swiprgesturerecognizer
类似
class MyViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
var recognizer = UISwipeGestureRecognizer(target: self, action: "didSwipe")
self.tableView.addGestureRecognizer(recognizer)
}
func didSwipe(recognizer: UIGestureRecognizer) {
if recognizer.state == UIGestureRecognizerState.Ended {
let swipeLocation = recognizer.locationInView(self.tableView)
if let swipedIndexPath = tableView.indexPathForRowAtPoint(swipeLocation) {
if let swipedCell = self.tableView.cellForRowAtIndexPath(swipedIndexPath) {
// Swipe happened. Do stuff!
}
}
}
}
}
这是一个示例,请根据需要进行管理。您可以添加滑动手势的 direction
属性 来处理特定方向的滑动,例如 UISwipeGestureRecognizerDirection.Left
或 Right
.
您可以参考
希望这会有所帮助:)