gpt4 book ai didi

ios - 从编辑场景中展开后, TableView 单元格为空白。如果终止应用程序并再次打开,Table View 会正确显示

转载 作者:搜寻专家 更新时间:2023-10-31 21:47:45 25 4
gpt4 key购买 nike

我在最新的 Xcode 和 Swift 2.1 中遇到了一个奇怪的问题。我有一个包含照片的表格 View 。可以点击它的单元格来编辑它。编辑后,例如更改照片或文本,然后展开到 tableview。单元格为空。

我终止应用程序并再次打开应用程序。 TableView 显示正确。我可以在编辑的单元格中看到新照片和新文本。所以这意味着保存没有问题。

我使用 reloadRowsAtIndexPaths 来刷新编辑的单元格。下面是我的代码。

    @IBAction func unwindToTableView(sender: UIStoryboardSegue) {
if let sourceViewController = sender.sourceViewController as? BexMaintain, bex = sourceViewController.bex {
if let selectedIndexPath = tableView.indexPathForSelectedRow {
bexs[selectedIndexPath.row] = bex
tableView.reloadRowsAtIndexPaths([selectedIndexPath], withRowAnimation: .None)
}}}

这里是 cellForRowAtIndexPath

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! TableViewCell
// Fetches the appropriate meal for the data source layout.
let bex = bexs[indexPath.row]
cell.name.text = bex.name
//fetch thumbnail
let thumbnailURL = bexURL.URLByAppendingPathComponent(bex.thumbnail)
cell.file.image = UIImage(data: NSData(contentsOfURL: thumbnailURL)!)
//fetch enable
if bex.enable == false {
cell.enable.setOn(false, animated: false)
}
else {
cell.enable.setOn(true, animated: false)
}
return cell
}

下面是问题的截图。

table is loaded first time after edit scene, unwind to table view. the edited cell is blank

请大家帮忙建议。

最佳答案

我现在可以解决这个问题了。我注意到,有时单元格中会出现一个按钮或照片,但其位置与单元格的框架重叠。

所以我认为这可能是布局问题。然后我尝试将所有对象及其在 Cell 中的位置安装在与 iphone 肖像相关的所有尺寸类中。
现在问题解决了。

以前,我只处理“紧凑宽度,任何高度”的尺寸类。

我认为这是 Xcode 错误,在展开到 TableView 后,Xcode 将单元格布局为其他大小类,而不是第一次加载表时的相同大小类。该问题不仅发生在模拟器中,也发生在设备中。在更新 Xcode 到最新版本之前,我以前从未发现过这个问题。

更新 - 2016 年 5 月 10 日,我仍然认为 Final Value Size Class 不覆盖 Base Value size class 很奇怪。而且给每一个size class都安装objects和constraints是不正常的。所以我尝试了所有尺寸类的卸载对象和约束,除了紧凑宽度常规高度。问题又来了。

然后我尝试从 Storyboard中禁用尺寸类,在弹出窗口中询问时仅保留 iphone 布局,然后再次重新启用它。
现在问题消失了。更新后它一定是 Xcode 某处的错误,它会影响模拟器和已部署的设备。

关于ios - 从编辑场景中展开后, TableView 单元格为空白。如果终止应用程序并再次打开,Table View 会正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37100311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com