Special Project: When you tap on a cell, you get to select its image

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate

In viewdidload:
        myTable.dataSource = self
        myTable.delegate = self


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        //actions when you click on the row
        let img = UIImagePickerController()
        img.delegate = self
        img.sourceType = UIImagePickerControllerSourceType.photoLibrary
        self.present(img, animated: true, completion: nil)
        currentIndexPath = indexPath
    }
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
            let cell = myTable.cellForRow(at: currentIndexPath) as! MyTableCellTableViewCell
            cell.MyImageView?.image = image
            
        } else{
            print("Something went wrong")
        }
        
        self.dismiss(animated: true, completion: nil)
    }

Comments

Popular posts from this blog

Setting up a playground

Go to another page