我正在尝试使用tableVC中填充的数组将tableVC中的相同内容(text + image)传递给详细tableVC。

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

他们共享一个tableviewcell。

TableViewCell类:UITableViewCell {

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

tableVC
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]中的一个错误

detailVC
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
}

故事板
http://s18.postimg.org/mwkw5hf1l/image.png

最佳答案

要解决您的第一个错误,请将cell.img.image = UIImage[indexPath.row]更改为cell.img.image = theimg[indexPath.row]

关于ios - Swift:如何使用相同的tableviewcell将相同的文本和图像形式的tableVC传递给detailVC?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29056323/

10-13 03:56