import UIKit

class ListView:
UIViewController,UITableViewDataSource,UITableViewDelegate  {

    var data = ["Settings ", "Power", "Background Image",
      "My favorates","My collections","Music", "Videos", "Photos"]
    var detailImages : Array<UIImage> = [
     UIImage(named: "r1.png")!,
     UIImage(named: "r2.png")!,
     UIImage(named: "r4.png")!,
     UIImage(named: "r5.png")!,
     UIImage(named: "r6.png")!]

     override func viewDidLoad() {
          super.viewDidLoad()
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count
    }


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell",
          forIndexPath: indexPath)
        cell.textLabel?.text = data[indexPath.row]
        //cell.textLabel?.text = "Next View"

        // to show the alternate color in cells

        if  indexPath.row % 2 == 0 {
            cell.backgroundColor = UIColor.greenColor()
        } else

        {
            cell.backgroundColor = UIColor.whiteColor()
        }

        return cell
    }

    func tableView(tableView: UITableView,
      didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let nextView = self.storyboard?.instantiateViewControllerWithIdentifier("InterestViewController")
          as! InterestViewController

        self.navigationController?.pushViewController(nextView,
          animated: true)
    }

最佳答案

您可以声明财产

var detailImages = [UIImage]()


InterestViewController中,然后通过didSelectRowAtIndexPath方法将图像分配给该属性:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    guard let nextView = storyboard?.instantiateViewControllerWithIdentifier("InterestViewController") as? InterestViewController else {return}
    nextView.detailImages = detailImages
    navigationController?.pushViewController(nextView, animated: true)
}

关于ios - 如何将图像数组从tableView传递到另一个DetailView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38055148/

10-13 04:06