Hello I am trying to complete my task since 2 days but still no success searched everywhere , I want to select multiple rows from tableview cells (which contains 2 labels and one image) then I want to transfer into another vc and show in tableview , I am able to select multiple rows and get this type index from selected rows but now I don't know how to get data and transfer into another vc and show in table view please help I am getting selected rows index like this [[0, 1], [0, 2], [0, 3]
VC Code
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
@IBOutlet weak var tableview: UITableView!
var labone = ["1","2","3","4","5","6"]
var labtwo = ["a","b","c","d","e","f"]
var img = ["bag","bag","bag","bag","bag","bag"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func button(_ sender: Any) {
let selectedindexPath = tableview.indexPathsForSelectedRows
if(selectedindexPath != nil){
let toy = labone[0]
print(toy)
print(selectedindexPath) }
else{
print("null")
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return labone.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let name = cell.viewWithTag(1) as! UILabel
let name_two = cell.viewWithTag(2) as! UILabel
let imgg = cell.viewWithTag(3) as! UIImageView
name.text = labone[indexPath.row]
name_two.text = labtwo[indexPath.row]
imgg.image = UIImage(named: img[indexPath.row])
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath)
cell.contentView.backgroundColor = UIColor.yellow
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
// let selectedCell = tableview.cellForRow(at: indexPath)
if let label = cell?.contentView.viewWithTag(4) as? UIImageView {
label.image = UIImage(named: "check_disable")
}
}
}