When I use tableView.indexPathForSelectedRow()
, calling selectRowAtIndexPath
works perfectly. However, I am selecting multiple rows thus I am trying to use table.View.indexPathForSelectedRows() as [NSIndexPath]
Swift Compiler Error: NSIndexPath is not a subtype of NSIndexPath
Error has been resolved.
Edit Added For Loop, multiple selection still not happening.
//I initialized saveSelection globally
var saveSelection : [NSIndexPath]?
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
saveSelection = (drugTableView.indexPathsForSelectedRows() as [NSIndexPath])
}
override func viewWillAppear(animated: Bool)
{
if !selectedDrugs.isEmpty
{
for save : NSIndexPath in saveSelection! as [NSIndexPath]
{
self.drugTableView.selectRowAtIndexPath(save, animated: true, scrollPosition: UITableViewScrollPosition.None)
}
}
}
Thank you for your help.
Here's what I did:
Made a dictionary of IndexPaths. Used
didSelectRowAtIndexPath
anddidDeselectRowAtIndexPath
to add and remove key/value pairs to the dictionary.Inside
viewWillAppear
I usedvar indexForLoop = myDictionary.values.array
to as the indexPath set to pass into myFor Loop
Crossed my fingers and hoped for the best
thank you Lyndsey for your help!