Ios UIImage仅在选定单元格时显示在表格视图单元格中
因此,我在应用程序中使用SWRevealViewController作为辅助菜单 这是我的侧视控制器: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
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()