在UITableView单元格中的可重用单元格中出现问题

时间:2017-02-23 13:03:56

标签: ios swift uitableview swift3 reuseidentifier

我在单UITableViewCell中有两种设计。这是我想要的设计,并在加载viewController

时得到

Correct cell design 但滚动后我得到了以下结果。 InCorrect design

我认为这个问题是由UITableViewCell的可重用性引起的。这是我的cellForRowAtIndexPath代码

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "notificationCell", for: indexPath) as! NotificationTableViewCell
        cell.selectionStyle = .none
        cell.btnClose.tag = indexPath.row
        let noti_flag = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "noti_flag") //as! String
         let noti_flag_string = NSString(format: "%@", noti_flag as! CVarArg) as String

        cell.lbl_From.text = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "caller_id") as? String ?? ""

        if noti_flag_string == "0" {
            cell.lblTime.isHidden = true
            cell.imgThumbIcon.isHidden = true
            cell.lbl_remaining.isHidden = true
            cell.lbl_mm_text.text = "Missed call"
            cell.lbl_mm_text.font = cell.lbl_mm_text.font.withSize(23)

        }
        else{

            var startAttributedText = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "rebound_start_time") as! String
            var endAttributedText = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "rebound_end_time") as! String
            startAttributedText = Model.shared.convertLocalTimeToServer(timeString: startAttributedText,isTimeFromServer: true)
            endAttributedText = Model.shared.convertLocalTimeToServer(timeString: endAttributedText,isTimeFromServer: true)
            let dateString:String = startAttributedText + " - " + endAttributedText

            cell.lblTime.attributedText = convertStringToAttr(dateString: dateString)

            cell.lbl_remaining.text = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "remaining_time") as? String ?? ""

            cell.lbl_mm_text.text = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "mm_text") as? String ?? ""

            //cell.lbl_From.text = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "caller_id") as? String ?? ""

            let mm_type = (arrayNotificationList.object(at: indexPath.row) as! NSDictionary).object(forKey: "mm_type") as! String//"img"
            switch mm_type {
            case "img":
                cell.imgThumbIcon.image = UIImage(named: "thumb_camera")
            case "vid":
                cell.imgThumbIcon.image = UIImage(named: "thumb_video")
            case "aud":
                cell.imgThumbIcon.image = UIImage(named: "thumb_audio")
            case "str":
                cell.imgThumbIcon.image = UIImage(named: "thumb_sticker")
            case "txt":
                cell.imgThumbIcon.image = UIImage(named: "thumb_text")
            case "brd":
                cell.imgThumbIcon.image = UIImage(named: "thumb_brand")
            default:
                cell.imgThumbIcon.image = UIImage(named: "thumb_camera")
            }
        }


        return cell
    }

所以请帮我解决这个问题。提前致谢。

0 个答案:

没有答案