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

时间:2015-08-11 17:42:58

标签: ios swift parse-platform nsdate

我正在尝试将文本标签设置为两个对象之间的时差; 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"
                    }
                    }
                }
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

如果您的数据正确,并且您的单元格中需要显示一组词典。试试这个:

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