Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIImage仅在选定单元格时显示在表格视图单元格中_Ios_Swift_Uitableview_Uiimage - Fatal编程技术网

Ios UIImage仅在选定单元格时显示在表格视图单元格中

Ios UIImage仅在选定单元格时显示在表格视图单元格中,ios,swift,uitableview,uiimage,Ios,Swift,Uitableview,Uiimage,因此,我在应用程序中使用SWRevealViewController作为辅助菜单 这是我的侧视控制器: import UIKit class SideTableViewController: UITableViewController { override func viewDidLoad() { self.tableView.backgroundColor = UIColor.blackColor() } override func tableView(tableVie

因此,我在应用程序中使用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!
}
当我打开侧桌视图时,我只看到一点点图像:

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


有人知道我如何解决这个问题吗?谢谢

必须尝试更换

cell.setNeedsLayout()

cell.setNeedsDisplay()