如何将图像数组从tableView传递到另一个DetailView

时间:2016-06-27 13:23:32

标签: ios xcode swift uitableview

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

1 个答案:

答案 0 :(得分:1)

您可以声明属性

var detailImages = [UIImage]()
<{1>}中的

,并使用InterestViewController方法将您的图片分配给此媒体资源:

didSelectRowAtIndexPath