Ios 将表行操作与indexPath行分隔
所以我有一个表视图和一个自定义VC。 然后我有一个对象练习,属性为Ios 将表行操作与indexPath行分隔,ios,swift,action,cell,Ios,Swift,Action,Cell,所以我有一个表视图和一个自定义VC。 然后我有一个对象练习,属性为detailImage。 如何将表行操作中的indexPath.row放入我的prepareforsgue函数中 这将返回nil:self.tableView.indexPathForSelectedRow override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "details
detailImage
。
如何将表行操作中的indexPath.row
放入我的prepareforsgue
函数中
这将返回nil
:self.tableView.indexPathForSelectedRow
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "detailsSegue" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let destinationController = segue.destinationViewController as! DetailViewController
print(self.exercises[indexPath.row].image)
destinationController.detailImage = self.exercises[indexPath.row].image
print ("send")
}
}
}
在
editActionsForRowAtIndexPath
我让它工作了。这也许是一个肮脏的解决方案,但它是有效的
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let detailsAction = UITableViewRowAction(style: .Default, title: "Details", handler: {(action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
self.performSegueWithIdentifier("detailsSegue", sender: indexPath) //sender is the indexPath
}
)
然后在prepareforsgue
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "detailsSegue" {
let indexPath = sender!
let destinationController = segue.destinationViewController as! DetailViewController
print(self.exercises[indexPath.row].image)
可能有更好的方法..任何人都可以发表评论吗?而不是在代码中这样做:
if let indexPath = self.tableView.indexPathForSelectedRow {
试试这个:
if let indexPath = self.tableView.indexPathForSelectedRow() {
您不需要使用表行操作。你用动作本身来处理它。请看下面的示例,这是一个swift versionI get“Invalid use of”()调用非函数类型“nsindepath”的值“生成失败。自定义VC是表视图的数据源和委托吗?从editActionAtRow所在的主VC,它将数据源和委托连接到该表视图。还有几个问题-您使用的是哪个版本的Swift/Xcode?”?主VC是UITableViewController或UIViewController的子类吗?如果是UIViewController,您是否为tableView制作了插座?我使用最新的beta版本7.0 beta 6(7A192o),它是UITableViewController的子类。对不起,我对这件事如此不屑一顾。。。