gpt4 book ai didi

ios - swift : How do I pass the same text and image form tableVC to a detailVC using the same tableviewcell?

转载 作者:可可西里 更新时间:2023-11-01 02:23:45 25 4
gpt4 key购买 nike

我正在尝试使用在 tableVC 中填充的数组将相同的(文本 + 图像)从 tableVC 传递到详细信息 tableVC。

它在 tableVC 中工作,但没有数据传递到 detailVC。

他们共享一个 tableviewcell。

类 TableViewCell:UITableViewCell {

@IBOutlet var img: UIImageView!
@IBOutlet var title: UILabel!
}

表VC

class TableViewController: UITableViewController {

var thecourseName = [String]()
var theimg = [UIImage]()


override func viewDidLoad() {
super.viewDidLoad()

thecourseName = ["course 1 ","course 2 ","course 3 "]
theimg = [UIImage(named: "109.png")!,UIImage(named: "110.png")!]
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TableViewCell

// Configure the cell...

cell.title.text = thecourseName[indexPath.row]
cell.date.text = date[indexPath.row]
cell.img.image = UIImage[indexPath.row]

return cell
}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if ( segue == "toInfo") {
var text = self.tableView.indexPathForSelectedRow()
var detailsVC: DetalisTableViewController = segue.destinationViewController as! DetalisTableViewController
detailsVC.courseName = thecourseName

}

}

`cell.img.image = UIImage[indexPath.row] 中的一个错误

细节VC

import UIKit

类 DetalisTableViewController: UITableViewController {

   var courseName = [String]()

@IBOutlet var passedCourse: UILabel!

override func viewDidLoad() {
super.viewDidLoad()


// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return courseName.count
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TableViewCell

// Configure the cell...

cell.title.text = courseName[indexPath.row]




return cell
}

Storyboard http://s18.postimg.org/mwkw5hf1l/image.png

最佳答案

要修复第一个错误,请将 cell.img.image = UIImage[indexPath.row] 更改为 cell.img.image = theimg[indexPath.row]

关于ios - swift : How do I pass the same text and image form tableVC to a detailVC using the same tableviewcell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29056323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com