如何在Tableviewcell和新日期中获得新行?

时间:2017-11-08 14:22:18

标签: swift uitableview parse-platform nsdata

告诉我如何做一个朋友,这样当你从服务器下载新的单元格时,函数“insertRow”不会添加,不可能在表的顶部获得一行。当你加载一个新单元格,旧信息的日期变为诸如加载一个相同的新信息时。告诉我如何确保日期是新的,旧的日期没有改变,细胞成为最重要的。我将非常感谢任何帮助!

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let sportCell = tableView.dequeueReusableCell(withIdentifier: "sportCell", for: indexPath) as! TableViewCell


                switch (segmentControl.selectedSegmentIndex)  {
            case 0 :



                let soccer = soccerString[indexPath.row]

                sportCell.matchLabel.text = soccer.matchS
                            soccerString[indexPath.row].imagePrS.getDataInBackground {(data, error) in
                sportCell.imageMatch.image = error == nil ? UIImage(data: data!) : nil
                    }

                break
            case 1 :

                let basket = basketString[indexPath.row]
                sportCell.matchLabel.text = basket.matchB
                basketString[indexPath.row].imagePrB.getDataInBackground {(data, error) in
                    sportCell.imageMatch.image = error == nil ? UIImage(data: data!) : nil

                }
                break
            case 2:
                sportCell.matchLabel.text = tennisString[indexPath.row].matchT

                tennisString[indexPath.row].imagePrT.getDataInBackground {(data, error) in
                        sportCell.imageMatch.image = error == nil ? UIImage(data: data!) : nil

                }
               break
            default:
                break

                }
            sportCell.selectionStyle = UITableViewCellSelectionStyle.none

            let date = Date()
            let calendar = Calendar.current



            let dateFormatter = DateFormatter()

            dateFormatter.dateStyle = .short
            dateFormatter.timeStyle = .short
            dateFormatter.locale = Locale(identifier: "ru_UA")
            dateFormatter.doesRelativeDateFormatting = true


            if let today = calendar.date(byAdding: .day, value: 0, to: date) {
                let todayString = dateFormatter.string(from: today)
                sportCell.dataSave.text = todayString

            } else if let yesterday = calendar.date(byAdding: .day, value: -1, to: date) {
                let yesterdayString = dateFormatter.string(from:yesterday)
                sportCell.dataSave.text = yesterdayString
            } else {
                sportCell.dataSave.text = dateFormatter.string(from: date)

            }



                return sportCell
 }

0 个答案:

没有答案