Ios tableViewCell.roundCorners不会立即显示

Ios tableViewCell.roundCorners不会立即显示,ios,swift,tableview,cell,Ios,Swift,Tableview,Cell,对于collectionViewCell,我有以下方法 cell.restarauntImage.roundCorners([.TopLeft, .TopRight], radius: 10, borderColor: UIColor.clearColor(), borderWidth: 0) cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), bord

对于collectionViewCell,我有以下方法

cell.restarauntImage.roundCorners([.TopLeft, .TopRight], radius: 10, borderColor: UIColor.clearColor(), borderWidth: 0)
cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
和tableViewCell

cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
问题是,它与collectionView完美配合,但在tableView中,它不能立即与.TopRight配合使用。然而,只有在我多次重复使用单元格时,它才适用。TopLeft起作用。另外,如果我删除.toplight并尝试仅应用于.toplight,它也不会起作用。有什么问题吗

cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
更新:在堆栈溢出上找到扩展

cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
extension UIView {
func roundCorners(corners:UIRectCorner, radius: CGFloat, borderColor: UIColor, borderWidth: CGFloat)
{
    let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
    let mask = CAShapeLayer()
    mask.path = path.CGPath
    self.layer.mask = mask
    addBorder(mask, borderWidth: borderWidth, borderColor: borderColor)
}

private func addBorder(mask: CAShapeLayer, borderWidth: CGFloat, borderColor: UIColor) {
    let borderLayer = CAShapeLayer()
    borderLayer.path = mask.path
    borderLayer.fillColor = UIColor.clearColor().CGColor
    borderLayer.strokeColor = borderColor.CGColor
    borderLayer.lineWidth = borderWidth
    borderLayer.frame = bounds
    layer.addSublayer(borderLayer)
}
}
更新2:CellForRowatineXpath,我尝试在ink_setImage之后将此方法应用于每个案例,但它也不起作用

cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("searchCell" , forIndexPath: indexPath) as! SearchTableViewCell
        cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 10, borderColor: UIColor.clearColor(), borderWidth: 0)
        cell.backgroundGray.roundCorners([.BottomLeft, .BottomRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
        switch (indexPath.row) {
        case 0:
            cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
        case 1:
            cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
        case 2:
            cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
        case 3:
            cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
        default:
            cell.restImage.hnk_setImageFromURL(NSURL(string: "https://pp.vk.me/c636117/v636117560/29385/OukzPhoe4q0.jpg")!)
        return cell
}
}

尝试在
viewDidLoad
方法的末尾添加一个
self.tableView.reloadData()
调用,这可能会解决延迟问题。

您的实现似乎太复杂,无法仅为imageView设置角半径。
cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
你所要做的就是:

cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
imageView.layer.cornerRadius = <the radius>

最后我在dispatch_async中添加了这个函数

cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
dispatch_async(dispatch_get_main_queue(),{
self.content.layer.borderWidth = 1
self.content.layer.borderColor = UIColor(red: 235/255, green: 235/255, blue: 235/255, alpha: 1).CGColor
self.restarauntImage.roundCorners([.TopLeft, .TopRight], radius: 6, borderColor: UIColor.clearColor(), borderWidth: 0)
self.content.roundCorners([.BottomLeft, .BottomRight], radius: 6,  borderColor: UIColor(red: 235/255, green: 235/255, blue: 235/255, alpha: 1),  borderWidth: 1)})
}

cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
此外,如果动态更改单元格中的视图数量(例如,可以隐藏底部的视图),则必须在cellForIndexPath中添加这些代码行,以使可重用单元格正确绘制边框

cell.restImage.roundCorners([.TopLeft, .TopRight], radius: 7, borderColor: UIColor.clearColor(), borderWidth: 0)
    cell.bottomDataView.hidden = false //show elements you have hidden
    cell.backgroundGray.layer.mask = nil //delete previous mask
    if cell.bottomDataView.layer.sublayers?.count > 2 {
        cell.bottomDataView.layer.sublayers?.removeLast() //delete previous layer
    }

您的圆角方法是什么样的?这不是UIKit提供的方法…为topicshow us CellForRowatineXpath方法添加了扩展代码。请仅为顶部2个角设置此半径,而不是为所有4got设置此半径。你试过cliptobunds=true吗?这可能会有帮助是的,我对我的形象和观点都做了,没有帮助。