ios – UIImageView隐藏在Xcode8和Swift3中
发布时间:2020-12-14 17:35:44 所属栏目:百科 来源:网络整理
导读:我的问题很简单:如果我尝试通过cellForRowAtIndexpath方法访问它,我的自定义UITableViewCell中的@IBOutlet UI ImageView将被隐藏. 我听说这是一个Swift 3或Xcode 8问题(这是有道理的,因为我刚刚更新后有这个问题).我遇到了与UIImageView相同的问题,并发现它
我的问题很简单:如果我尝试通过cellForRowAtIndexpath方法访问它,我的自定义UITableViewCell中的@IBOutlet UI
ImageView将被隐藏.
我听说这是一个Swift 3或Xcode 8问题(这是有道理的,因为我刚刚更新后有这个问题).我遇到了与UIImageView相同的问题,并发现它被隐藏的原因是因为我在周期中过早地调用它.从最新的更新开始,如果我尝试从nib访问@IBOutlet,我只能在viewDidAppear方法中这样做.如果我尝试viewDidLoad或viewWillLoad方法,那么插座将被隐藏. 在这种情况下,我只是通过以下两行代码将UIImageView从正方形更改为圆形: cell.pictureImageView.layer.cornerRadius = cell.pictureImageView.frame.size.width / 2; cell.pictureImageView.clipsToBounds = true; 同样,这仅适用于vieDidAppear方法.是否有UITableViewCell的viewDidAppear方法?我在cellForRowAtIndexPath中放了相同的两行,图像消失了: func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: K.Cell,for: indexPath) as! TimelineTableViewCell //Turn profile picture into a circle cell.pictureImageView.layer.cornerRadius = cell.pictureImageView.frame.size.width / 2; cell.pictureImageView.clipsToBounds = true; return cell } 我也在自定义单元格的awakeFromNib方法中尝试过,同样的事情发生了……图像消失了: override func awakeFromNib() { super.awakeFromNib() cell.pictureImageView.layer.cornerRadius = cell.pictureImageView.frame.size.width / 2; cell.pictureImageView.clipsToBounds = true; } 非常感谢任何帮助,谢谢大家! 干杯, C 解决方法
你太早说了. pictureImageView还没有已知的宽度.
你需要调用layoutIfNeeded: cell.pictureImageView.layoutIfNeeded() cell.pictureImageView.layer.cornerRadius = cell.pictureImageView.frame.size.width / 2 cell.pictureImageView.clipsToBounds = true 圆圈是: init UIViewController awakeFromNib loadView // your pictureImageView is loaded here UIView awakeFromNib UIViewController viewDidLoad viewWillAppear viewDidAppear // the properties of your pictureImageView are available here (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |