有人可以帮我修复这个Xcode以进行UICollection吗?

时间:2015-11-30 17:56:14

标签: ios uicollectionview nsuserdefaults xcode7 nsdata

有人可以帮我解决这个问题吗?我正在尝试扩展我在集合视图中单击的图像,但它会扩展我选择的上一个图像。我认为我错误地使用NSUserDefaults,但我不确定。这是Xcode7测试版软件。

import UIKit

class PortfolioDetail: UIViewController {

  @IBOutlet var DetailImageView: UIImageView!

  @IBOutlet var DetailLabel: UILabel!

  var name: AnyObject? {

    get {

    return NSUserDefaults.standardUserDefaults().objectForKey("name")

    }

  }

  override func viewDidLoad() {

    self.view.backgroundColor = UIColor(patternImage: UIImage(named: "BackgroundImage.png")!)

    DetailImageView.image = UIImage(named: name as! String)

    /* if DetailImageView.image == UIImage(named: "PortImage1") {

    DetailLabel.text = "Portfolio image 1"

  }

  if DetailImageView.image == UIImage(named: "PortImage2") {

    DetailLabel.text = "Portfolio image 2"

  }

  if DetailImageView.image == UIImage(named: "PortImage3") {

    DetailLabel.text = "Portfolio image 3"

  }

  if DetailImageView.image == UIImage(named: "PortImage4") {

    DetailLabel.text = "Portfolio image 4"

  }

  if DetailImageView.image == UIImage(named: "PortImage5") {

    DetailLabel.text = "Portfolio image 5"

  }

  if DetailImageView.image == UIImage(named: "PortImage6") {

    DetailLabel.text = "Portfolio image 6"

  }

  if DetailImageView.image == UIImage(named: "PortImage7") {

    DetailLabel.text = "Portfolio image 7"

  }

  */

  super.viewDidLoad()

    // Do any additional setup after loading the view.

  }

  override func didReceiveMemoryWarning() {

    super.didReceiveMemoryWarning()

    // Dispose of any resources that can be recreated.

  }

1 个答案:

答案 0 :(得分:0)

您正在使用NSUserDefaults来获取图片,但您没有保存任何更改。您还需要更新NSUserDefaults。 此外,下次请将您的代码添加为问题中的文字。