Does anyone know how to keep the rows selected/highlighed in UITableView when you move from a new View Controller back to your 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:
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'
Could someone help me out with this one, this is such a headache.
Thank you.
尝试在表视图控制器clearsSelectionOnViewWillAppear
设置为false。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.