Swift链接图像从使用seguesparsing数组到secondViewController
这里是我的代码,我试图使用“prepareForSegue”函数从tableViewController(firstViewController)发送到我的detailedViewController(secondViewController)的图像。 我已经设法从parsing云成功填充我的firstViewController,我设法得到我的secondViewController标签更新,但我无法得到imageView更新。 我已经发布了我的代码如下
firstViewController
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
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 }
请有人可以帮我弄清楚,林有点新的整个事情
她的保存代码,我想你想看到…
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let myCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! EventsCell postedImages[indexPath.row].getDataInBackgroundWithBlock { (data, error) -> Void in if let downloadedImage = UIImage(data: data!) { myCell.postedEventImage.image = downloadedImage } } myCell.eventName.text = postedEvents[indexPath.row] myCell.eventStart.text = postedStart[indexPath.row] myCell.eventPrice.text = postedPrices[indexPath.row] return myCell }
然后还有这个代码如何追加到我的postImages数组
if let objects = objects { for object in objects { self.postedImages.append(object.objectForKey("Image") as! PFFile) self.tableView.reloadData() }
看起来你应该在secondViewController中定义一个UIImageView而不是UIImage。 你的detailImageView
需要是UIImageView
types的。 你写它的方式,它是types的UIImage
。
在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中看起来像这样:
if let myIndexPath = tableView.indexPathForSelectedRow? { let cell = self.tableView.cellForRowAtIndexPath(myIndexPath) eventDetailVC.detailImageView.image = cell.postedEventImage.image }
在secondViewController的viewDidLoad中你的其他任务也有点不同寻常。 您似乎根据您如何命名它们来从UILabels分配文本值。 如果一个variables是一个UILabel比让它命名一些标签是合适的。 但是,如果types是一个string,它们是基于您的variables赋值,而不是命名的东西标签可能是一个混淆的来源。