使用 segues 将 Parse 数组中的图像快速链接到 secondViewController [英] Swift link Image from Parse array using segues to secondViewController

查看:11
本文介绍了使用 segues 将 Parse 数组中的图像快速链接到 secondViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我正在尝试使用prepareForSegue"功能将图像从 tableViewController (firstViewController) 发送到我的 detailViewController (secondViewController).我已经成功地从解析云中填充了我的 firstViewController 并且我已经设法让我的 secondViewController 标签更新,但我无法更新 imageView.我已经在下面发布了我的代码

Here is my code, i am trying to use the "prepareForSegue" function to send an image from tableViewController (firstViewController) to my detailedViewController (secondViewController). I have managed to populate my firstViewController from the parse cloud successfully and I have managed to get my secondViewController Labels to update, but i can not get the imageView to update. I have posted my code below

第一个视图控制器

    override func prepareForSegue(segue: UIStoryboardSegue, sender:      AnyObject?) {

    let eventDetailVC: EventDetailsVC = segue.destinationViewController as!  EventDetailsVC
    if let selectedArrayIndex = tableView.indexPathForSelectedRow?.row {

        eventDetailVC.detailNameLabel = postedEvents[selectedArrayIndex]
        eventDetailVC.detailAddressLabel = postedAddress[selectedArrayIndex]
        eventDetailVC.detailCityLabel = postedCity[selectedArrayIndex]
        eventDetailVC.detailStateLabel = postedState[selectedArrayIndex]
        eventDetailVC.detailStartLabel = postedStart[selectedArrayIndex]
        eventDetailVC.detailEndLabel = postedEnd[selectedArrayIndex]
        eventDetailVC.detailPriceLabel = postedPrices[selectedArrayIndex]
        eventDetailVC.detailDescriptionLabel =    postedDescription[selectedArrayIndex]

        // The error is here....i think
        eventDetailVC.detailImageView.image = image

    }
}

secondViewController

secondViewController

   var detailNameLabel = String()
   var detailDescriptionLabel = String()
   var detailPriceLabel = String()
   var detailStartLabel = String()
   var detailEndLabel = String()
   var detailAddressLabel = String()
   var detailCityLabel = String()
   var detailStateLabel = String()
   var detailImageView = UIImage()

   override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    detailName.text = detailNameLabel
    detailDescription.text = detailDescriptionLabel
    detailPrice.text = detailPriceLabel
    detailStart.text = detailStartLabel
    detailEnd.text = detailEndLabel
    detailAddress.text = detailAddressLabel
    detailCity.text = detailCityLabel
    detailState.text = detailStateLabel

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

请有人帮我解决这个问题,我对这整个事情有点陌生

Please can someone help me figure this out, Im kinda new to this whole thing

推荐答案

看起来您应该在 secondViewController 中定义 UIImageView 而不是 UIImage.你的 detailImageView 需要是 UIImageView 类型.按照您的编写方式,它属于 UIImage 类型.

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.

在 secondViewController 中,替换

In secondViewController, replace

var detailImageView = UIImage()

var detailImageView = UIImageView()

然后改变:

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

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

要处理从表格视图单元格发送到第二个视图控制器的图像,需要从所选单元格中抓取图像.这在你的 prepareForSegue 中看起来像这样:

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 
}

<小时>

你在 secondViewController 中的 viewDidLoad 中的其他分配也有点不寻常.您似乎是根据您的命名方式从 UILabels 分配文本值.如果变量是 UILabel,则将其命名为 somethingLabel 比较合适.但是,如果类型是 String,它们基于您的变量分配,那么将其命名为 somethingLabel 可能会造成混淆.


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.

这篇关于使用 segues 将 Parse 数组中的图像快速链接到 secondViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆