【问题标题】:UITableViewCell wrong layout after selection in swiftswift中选择后UITableViewCell布局错误
【发布时间】:2015-01-05 13:57:43
【问题描述】:

我尝试使用默认的 tableview 单元格创建 tableview。每个单元格都有 imageView 和标题。从服务器异步加载的图像。为此,我使用 Alamofire 框架。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let CellID: NSString = "Cell"
        let cell = UITableViewCell(style:  UITableViewCellStyle.Default, reuseIdentifier: CellID)

        cell.textLabel!.text = "test #\(indexPath.row)"
        var imageURL = repArray[indexPath.row]["image"]!!

        cell.imageView!.image = UIImage(named: "recept")

        Alamofire.request(.GET, imageURL).response() {
            (_, _, data, _) in

            let image = UIImage(data: data! as NSData)
            dispatch_async(dispatch_get_main_queue(), {
                if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
                    cellToUpdate.imageView!.image = image
                }
            })

        }

        return cell
    }

但是当我选择任何 tableview 单元格时,imageview 的大小会发生变化。

为什么会这样?

【问题讨论】:

    标签: image uitableview swift alamofire


    【解决方案1】:

    您有tableView:didSelectRowAtIndexPathtableView:willSelectRowAtIndexPath 方法吗?如果你这样做,你能展示它的样子吗?看起来这是您更改单元格布局的部分。

    【讨论】:

    • 您的问题解决了吗?我遇到了完全相同的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多