标签在UITableViewCell中重叠 - Swift

时间:2017-05-11 10:28:04

标签: ios swift uitableview tableviewcell

我们正在远离目标c并在Swift中实现新代码。我遇到了UITableViewCells的问题。每当我在单元格中添加内容并使用UITableView显示它时,单元格的内容就会变得杂乱无章。如何防止“ques”“ans”标签重叠?

运行应用时的输出:

enter image description here

类控制器如下:

@objc public class ProfileViewController :UITableViewDelegate, UITableViewDataSource {
    @IBOutlet weak var detailTableView: UITableView! //connected to storyboard
    public override func viewDidLoad() {
        super.viewDidLoad()
        self.detailTableView.delegate = self;
        self.detailTableView.dataSource = self;
        self.detailTableView.register(UINib(nibName: "DetailTableViewCell", bundle: nil), forCellReuseIdentifier: "DetailTableViewCell")
    }

    public override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }

    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }

    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "DetailTableViewCell", for: indexPath) as! DetailTableViewCell
        return cell
    }

}

DetailTableViewCell类

@objc public class DetailTableViewCell: UITableViewCell {
   public override func awakeFromNib() {
        super.awakeFromNib()
    }
    public override func prepareForReuse() {
        super.prepareForReuse()
    }
    public override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }   
}

细胞类的Xib

xib view of cell class

控制器的故事板视图

storyboard view of controller

我相信我错过了一些非常明显的东西,因为我准确地定义了所有约束。我可以请一些提示吗?

0 个答案:

没有答案
相关问题