所以我一直试图让任何一行像下一堂课一样,有点像向左滑动你可以在添加func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
之后删除该行
但我不想删除它,而是希望它显示另一个类。如果有人能提供帮助,那将非常感谢
答案 0 :(得分:0)
如果我正确理解了这个问题,你会希望用户在一个单元格上向左滑动,它会触发一个segue吗?
如果是这种情况,您可以尝试在UITableViewDataSource类的addGestureRecognizer
方法中使用cellForRow
方法向单元格添加UISwipeGestureRecognizer。
希望这有帮助!
答案 1 :(得分:0)
您可以添加 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
这是一个例子,根据您的需要进行管理。您可以添加swipegesture的UISwipeGestureRecognizerDirection.Left
属性来处理特定方向的滑动,例如Right
或public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!isDeviceSupportCamera()) {
Toast.makeText(getApplicationContext(),
"Sorry! Your device doesn't support camera",
Toast.LENGTH_LONG).show();
// will close the app if the device does't have camera
finish();
}
}
private boolean isDeviceSupportCamera() {
if (getApplicationContext().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA)) {
// this device has a camera
return true;
} else {
// no camera on this device
return false;
}
}
}
。
您可以参考this answer作为参考。
希望这会有所帮助:)