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

标签 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"
                    }
                    }
                }
            }
        }
    }

最佳答案

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

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

关于ios - 将文本标签设置为时间间隔的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31948496/

相关文章:

ios - 在 iOS5 的 uitextfield 中禁用粘贴

objective-c - Xcode链接错误 "symbol(s) not found for architecture x86_64"

ios - 解析/PFQueryTableView : Append extra text to an object in parse

android - 如何隐藏我的 Parse.com API key ?

swift - 在 swift 中使用 parse 重置密码

iphone - iPhone用户联系信息

ios - NSData.write 在 iOS 8 上触发 ECX_BAD_ACCESS

json - Swift 3 字典 JSON

swift - 添加将对象添加到 PFUser

c# - 根页面不是 Navigation.NavigationStack 集合的一部分