选择单元格时,UIImage仅出现在表格视图单元格中

时间:2016-04-17 23:45:32

标签: ios swift uitableview uiimage

所以我在我的应用程序中使用SWRevealViewController作为侧边菜单。

这是我的侧视图控制器:

import UIKit

class SideTableViewController: UITableViewController {
  override func viewDidLoad() {
    self.tableView.backgroundColor = UIColor.blackColor()
  }

  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 5
  }

  override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
  }

  override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
    print("You selected cell #\(indexPath.row)!")
  }

  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    if indexPath.row == 0 {
      let cell: FirstTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("FirstCell") as! FirstTableViewCell
      cell.textLabel?.text = "First Cell"
      cell.backgroundColor = UIColor.blackColor()
      cell.textLabel?.textColor = UIColor.whiteColor()
      cell.cellImage.image = UIImage(named: "person")
//      cell.imageView?.image = UIImage(named: "person")
      cell.setNeedsLayout()
      return cell
    } else {
      let cell = tableView.dequeueReusableCellWithIdentifier("Cell")!
      cell.textLabel?.text = "Other Cell"
      cell.backgroundColor = UIColor.blackColor()
      cell.textLabel?.textColor = UIColor.whiteColor()
      return cell
    }
  }

  override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row == 0 {
      return 200
    } else {
      return 50
    }
  }
}

这是我使用名为FirstTableViewCell的自定义表格视图单元格:

import UIKit

class FirstTableViewCell: UITableViewCell {
  @IBOutlet var cellImage: UIImageView!
}

当我打开边桌视图时,我只看到了我的一些图像:Image link

但是当我选择我的手机时,我可以看到整个图像!:Image link

有谁知道如何解决这个问题?谢谢!

1 个答案:

答案 0 :(得分:0)

必须尝试更换

cell.setNeedsLayout()

cell.setNeedsDisplay()
相关问题