ios - 当圆形蒙版应用于 ImageView 时,UIImageView 中的图像不显示在 UITableView 中,除非滚动

标签 ios swift uitableview uiimageview calayer

在此先感谢您的帮助。

我在主视图 Controller 中有一个 UITableView。在原型(prototype)单元格中,我有一个 UIImageview。在下面的代码中,一切正常,直到我添加 5 行以应用圆形蒙版和边框。一旦我这样做,除非我滚动单元格,否则图像将不会加载。然而, mask 和边框确实得到了完美的应用。当它起作用时会很棒......但在那之前。

当然,这以前见过。我是一个 swift/objective-C 新手。

正在为此快速工作。

下面的代码;

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("mixerCell", forIndexPath: indexPath) as! MixerTableViewCell

    // set label background color to clear
    cell.textLabel?.backgroundColor = UIColor.clearColor()

    // set highlight selection to none
    cell.selectionStyle = .None

    // set image for cell
    let imageView = cell.viewWithTag(1) as! UIImageView

    // put circular mask and border. This is the problem code that causes initial load of the tableview images to show up blank.
    imageView.layer.cornerRadius = imageView.frame.size.width / 2;
    imageView.clipsToBounds = true;

    let color1 = UIColor(white: 1.0, alpha: 0.5).CGColor as CGColorRef
    imageView.layer.borderWidth = 2;
    imageView.layer.borderColor = color1

    // assign image
    imageView.image = UIImage(named: mixerSounds[indexPath.row])

    return cell
}

initial view load

after scroll

最佳答案

您的代码非常适合我。我在这里使用 Xcode-7。我认为您使用的是 Xcode-6.3 或更低版本。只需将它升级到 Xcode- 7。如果您使用的是相同的,那么只需检查您的 heightforRowAtIndexpath 或其他代表应该有一些问题。 谢谢

关于ios - 当圆形蒙版应用于 ImageView 时,UIImageView 中的图像不显示在 UITableView 中,除非滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34083071/

相关文章:

swift - 调试 Realm ,调用堆栈没有任何应用程序代码

ios - TableView 单元格出现 Sigabrt 错误

ios - 如何修复媒体屏幕中断问题

javascript - 使用 JavaScript 查找选定文本的开始和结束索引

ios - 可选类型 '$T11' 不能用作 bool 值;自安装 XCode 6 beta 7 以来,改为测试 '!= nil'

ios - 条件绑定(bind)的初始化程序必须具有 Optional 类型,而不是 'Error.Protocol'

swift - 完成处理程序完成前为真

swift - 使用 Float 数组在 Swift 中调用 "realloc"的正确方法?

ios - Swift:Xcode tableView 无限滚动

iphone - UITableViewCell 选择器 setSelected :animated: gets called many times?