![](/img/trans.png)
[英]MFMailComposeViewController appears for a second then disappears
[英]Swift: table cell appears for a second and disappears
我在 UIViewController 中有一个父 UIView。 This parent UIView is put under segmented control such that when a different index is selected, this parent view brings to front the according added subviews (eg currentViewController().view).
var parentView: UIView!
var currentView: UIView!
override func viewDidLoad() {
currentView = currentViewController().view
parentUIView.addSubview(currentView)
parentUIView.bringSubview(currentView)
}
currentViewController 里面有一个 UITableView。 由于控制器是在 xib 下构建的,所以我在 currentViewController 中注册了单元格。 (示例代码如下)
import UIKit
class currentViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var stockInfo: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
stockInfo.delegate = self
stockInfo.dataSource = self
stockInfo.register(UITableViewCell.self, forCellReuseIdentifier: "something")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = stockInfo.dequeueReusableCell(withIdentifier: "something", for: indexPath) as! UITableViewCell
cell.textLabel?.text = "testing DEFAULT"
return cell
}
代码非常简单直接。 选择分段控件时,我检查索引并将此视图带到前面。 上面的代码只是一个例子。 我也有其他看法。
不幸的是,我的硬编码单元(为了调试方便)甚至没有出现超过一秒钟。 它们在第一次加载视图时出现,但在没有任何用户操作的情况下在一秒钟内消失。 我想他们被释放了? 或者有什么我不知道的原因? 有人可以帮忙吗? 我已经坚持了几个小时。
让我补充一点,我已经浪费了一整天的时间来弄清楚。 我的表格视图单元格在 reloadData() 后消失了。 解决方案是 -> 在 prepareForReuse() 中取消隐藏单元格,prepareForReuse() 用于单元格类本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.