将文本标签设置为时间间隔的差异

Setting text labels to the difference in time intervals

我正在尝试为两个对象之间的时间差设置一个文本标签;当前时间和 Parse 中保存的时间。我的问题是最后的 if/else 语句。标签都分配有 datesHours 或 datesMinutes 字典,而 datesHours 字典应仅在小时大于 1 时分配 - 否则,文本标签应显示分钟数。

我做错了什么?

 var datesHours = [Int: String]()
 var datesMinutes = [Int: String]()



      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {


    let cell = tableView.dequeueReusableCellWithIdentifier("MyCell") as! TableViewCell

    var query = PFQuery(className: "Items")

    query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in

        if error == nil {
            if let objects = objects {
                for (index, title) in enumerate(objects) {
                    let itemDate = (title as! PFObject)["date"] as! NSDate

                    var timeDifference = NSDate().timeIntervalSinceDate(itemDate)
                    var time = Int(timeDifference)
                    var minutes = ((time / 60) % 60)
                    var hours = (time / 3600)

                    self.datesHours[index] = String(hours)
                    self.datesMinutes[index] = String(minutes)
                    //println(self.datesMinutes)
                    //println(self.datesHours)

                    for (index, hour) in self.datesHours {

                    if hour == "\(0)" {
                        cell.timeLabel.text = self.datesMinutes[indexPath.row]! + "m"

                        } else  {
                        cell.timeLabel.text = self.datesHours[indexPath.row]! + "hr"
                    }
                    }
                }
            }
        }
    }

如果您的数据是正确的,并且您有一组字典需要显示在您的单元格上。试试这个:

cell.textLabel.text = [[mArray objectAtIndex:indexPath.row] objectForKey:@"HOUR OR MINUTE KEY"];