Swift link Image from Parse array using segues to secondViewController

前端 未结 2 2061
無奈伤痛
無奈伤痛 2021-01-23 23:35

Here is my code, i am trying to use the \"prepareForSegue\" function to send an image from tableViewController (firstViewController) to my detailedViewController (secondViewCont

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-24 00:16

    It looks like you should define a UIImageView instead of a UIImage in secondViewController. Your detailImageView will need to be of type UIImageView. The way you have it written, it is of type UIImage.

    In secondViewController, replace

    var detailImageView = UIImage()
    

    with

    var detailImageView = UIImageView()
    

    Then change:

    // its this line below....i think
    detailImage.image = detailImageView
    

    to

    // its this line below....i think
    detailImage.image = detailImageView.image
    

    To handle the image sending from the table view cell to the second view controller will require grabbing the image from the selected cell. This would look something like this in your prepareForSegue:

    if let myIndexPath = tableView.indexPathForSelectedRow? {
        let cell = self.tableView.cellForRowAtIndexPath(myIndexPath)
        eventDetailVC.detailImageView.image = cell.postedEventImage.image 
    }
    

    Your other assignments in viewDidLoad in secondViewController are also a bit unusual. You appear to be assigning the text values from UILabels based on how you are naming them. If a variable is a UILabel than having it named somethingLabel is appropriate. However, if the type is a String, which they are based on your variable assignments, than having it named somethingLabel can be a source of confusion.

提交回复
热议问题