tableviewcells的奇怪活动

时间:2018-02-19 02:05:51

标签: arrays swift uitableview dictionary

我有一个表格视图,每个单元格由一个图像和两个标签组成。当我创建每个单元格时,我调用一个名为createPostActivityCell的函数。此函数返回具有子视图和其他UI元素的单元格。当我调用该函数时,我还为该单元格指定了一个我希望它显示的标题,我从一个字典数组中指定它。它起初运作良好,但在向上和向下滚动后,标题开始叠加并产生奇怪的效果。

我的细胞类:

import UIKit

class ActivityCell: UITableViewCell{

@IBOutlet weak var cellView: UIView!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

func createPostActivityCell(cell: ActivityCell, cellImage: UIImage, cellIndex: IndexPath, cellTitle: String) -> ActivityCell{
    let cell = cell
    let profileObject = ProfileObject(profileImage: cellImage, profileName: "Zachary Gameiro", tag: cellIndex.row, isClickable: false, x: 5, y: 5, width: 50, height: 50)
    cellView.layer.masksToBounds = true
    cellView.layer.cornerRadius = 30

    // Title Label
    let titleLabel = UILabel(frame: CGRect(x: 60, y: 10, width: 200, height: 20))
    titleLabel.text = cellTitle
    titleLabel.font = UIFont(name: "Roboto-Regular", size: 15.0)

    // Description Label
    let descriptionLabel = UILabel(frame: CGRect(x: 60, y: 30, width: 200, height: 20))
    descriptionLabel.text = "My Party is at 6:00"
    descriptionLabel.font = UIFont(name: "Roboto-Light", size: 12.0)

    cellView.addSubview(profileObject.createView())
    cellView.addSubview(titleLabel)
    cellView.addSubview(descriptionLabel)
    return cell
}


}

这是我如何称呼细胞

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = activityTableView.dequeueReusableCell(withIdentifier: "activityCell") as! ActivityCell
    cell = cell.createPostActivityCell(cell: cell, cellImage: #imageLiteral(resourceName: "cosmonauts_playing_tennis_kit8-net_1x.png"), cellIndex: indexPath, cellTitle: self.activityCellData[indexPath.row]["title"] as! String)
    return cell
}

并且是dicitonary

var activityCellData:[[String:Any]] = [["title":"Party"],["title":"wdq"],["title":"Party"],["title":"cow"],["title":"Party"],["title":"Party"],["title":"Party"],["title":"Party"],["title":"Party"],["title":"Party"]]

This Is What I Want To Happen This Is What Happens After A Couple Scrolls Up And Down

0 个答案:

没有答案