[英]Keep selected rows when dismissing UITableViewController - Swift, UITableView
Does anyone know how to keep the rows selected/highlighed in UITableView when you move from a new View Controller back to your UITableView? 当您从新的View Controller返回到UITableView时,有人知道如何在UITableView中保持选定的行/高行吗?
When I make a selection and dismiss the table view controller, the selection is no longer there when I return. 当我做出选择并关闭表视图控制器时,返回时该选择不再存在。 I set clearsSelectionOnViewWillAppear to false inside
super.viewDidLoad
but that didn't work, someone on StackOverflow mentioned doing the following: 我在
super.viewDidLoad
内部将clearsSelectionOnViewWillAppear设置为false,但这没有用,StackOverflow上的某人提到要执行以下操作:
class TableViewController:
UITableViewController,
UITableViewDelegate,
UITableViewDataSource {
@IBOutlet weak var drugTableView: UITableView!
override func viewDidLoad()
{
super.viewDidLoad()
self.clearsSelectionOnViewWillAppear = false
}
override func viewWillAppear(animated: Bool) {
let indexPaths = self.drugTableView.indexPathsForSelectedRows() as [NSIndexPath]
self.tableView.selectRowAtIndexPath(indexPath: indexPaths, animated: true, scrollPosition: UITableViewScrollPosition.None)
}
but that won't compile due to this error: 但是由于以下错误而无法编译:
self.tableView.selectRowAtIndexPath(indexPath: indexPaths, animated: true, scrollPosition: UITableViewScrollPosition.None)
Cannot convert the expression's type '(indexPath: [AnyObject]?, animated: BooleanLiteralConvertible, scrollPosition: UITableViewScrollPosition)' to type 'BooleanLiteralConvertible' self.tableView.selectRowAtIndexPath(indexPath: indexPaths, animated: true, scrollPosition: UITableViewScrollPosition.None)
无法将表达式的类型'(indexPath:[AnyObject]?
Could someone help me out with this one, this is such a headache. 有人可以帮我解决这个问题,这太令人头疼了。
Thank you. 谢谢。
尝试在表视图控制器clearsSelectionOnViewWillAppear
设置为false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.