我在跑步时遇到了撞车,它指向了dateFormmater.timezone.控制台中的错误是:
无法将'Swift.Optional'(0x1192bf4a8)类型的值转换为'NSTimeZone'(0x1192c0270).
价值rowEvents.date是"1480134638.0"
我试图从Firebase中取出一个Unix时间戳保存为字符串.将其转换为Date并再次将其保存为字符串,以便将其发布到单元格标签上.
我从StackOverflow获得了这段代码.我插入了我的数据,一切都很好,直到我运行它.我想一切都不是很好......
if let lastUpdated : String = rowEvents.date {
    let epocTime = TimeInterval(lastUpdated)! / 1000 // convert it from milliseconds dividing it by 1000
    let unixTimestamp = NSDate(timeIntervalSince1970: epocTime) //convert unix timestamp to Date
    let dateFormatter = DateFormatter()
    dateFormatter.timeZone = NSTimeZone() as TimeZone!
    dateFormatter.locale = NSLocale.current // NSLocale(localeIdentifier: "en_US_POSIX")
    dateFormatter.dateFormat =  "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
    dateFormatter.date(from: String(describing: unixTimestamp))
    let updatedTimeStamp = unixTimestamp
    let cellDate = DateFormatter.localizedString(from: updatedTimeStamp as Date, dateStyle: DateFormatter.Style.full, timeStyle: DateFormatter.Style.medium)
    cell.subtitleLabel.text …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
if let date = messages?.date{
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = "h:mm a"
            //let elapseTimeInSeconds = NSDate.timeIntervalSince(date)
            let elapseTimeInSeconds = Date(timeIntervalSinceNow: (date as? Date))
            let secondsInDays: TimeInterval = 60 * 60 * 24
            if elapseTimeInSeconds > secondsInDays {
                dateFormatter.dateFormat = "EEE"
            } else if elapseTimeInSeconds > 7 * secondsInDays {
                dateFormatter.dateFormat = "MM/dd/yy"
            }
            timeLabel.text = dateFormatter.string(from: date as Date)
        }
Run Code Online (Sandbox Code Playgroud)
这是错误:
无法转换"日期"类型的值?预期参数类型'TimeInterval'(又名'Double')
错误在这一行:
let elapseTimeInSeconds = Date(timeIntervalSinceNow: (date as? Date))
Run Code Online (Sandbox Code Playgroud)
我已经尝试过我所知道的并且没有任何效果.请帮忙.
让我直截了当地说明logcat中的错误是:
Could not complete scheduled request to refresh entries. ClientErrorCode: 3
Run Code Online (Sandbox Code Playgroud)
我测试了代码的Realm()部分并获取了正确的数据.基本上,应用程序只是在加载该Activity时崩溃.我现在尝试做的就是在每个单元格中发布itemName.如果你们需要logcat,就这么说吧我会发布它.还需要任何其他细节.
这是我的Activity的代码,每个单元格中只有一个ImageView和一个TextView的recyclerView:
class EssentialsActivity : AppCompatActivity() {
    var category: String? = null
    val realmtypeFunctions = RealmTypeFunctions()
    var realmResults: RealmResults<ChattRItem>? = null
    var chattRItemList = mutableListOf<ChattRItem>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_essentials)
        //init realm
        Realm.init(this)
        category = "People"
        recyclerView_Essentials.setBackgroundColor(Color.CYAN)
        recyclerView_Essentials.layoutManager = GridLayoutManager(this, 3)
//        AsyncTask.execute {
            category?.let {
                loadFromRealm(it)
            }
//        }
        this.runOnUiThread {
            recyclerView_Essentials.adapter = EssentialsAdapter(chattRItemList)
        }
    }
    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        val inflater = menuInflater …Run Code Online (Sandbox Code Playgroud) 我的问题是尝试将日期选择器结果转换为unix时间戳.我的客户坚持要将其作为unix时间戳保存到Firebase数据库中.我也很新,所以......
let myTimeStamp = NSDate(timeIntervalSince1970: self.datePicker?.date)
Run Code Online (Sandbox Code Playgroud)
这是datePicker的结果:2016-12-03 00:56:00 +0000这是错误:无法转换'Date?'类型的值 预期参数类型'TimeInterval'(又名'Double')
请帮助先生和女士!
我正在尝试在 tableview 中的每个单元格上放置一个带有圆角半径的虚线边框。
我的代码:
fileprivate func drawDashedBorder(_ indexPath: IndexPath, _ cell: OpenJobsCell) {
    //dashed border for drafts
    if jobObjects[indexPath.section].sectionName == "DRAFT" {
      if let theView = cell.containerView {
        let rect = theView.bounds
        let layer = CAShapeLayer.init()
        let path = UIBezierPath(roundedRect: rect, cornerRadius: 8)
        layer.path = path.cgPath
        layer.strokeColor = UIColor.lightGray.cgColor
        layer.lineDashPattern = [3,3]
        layer.backgroundColor = UIColor.clear.cgColor
        layer.fillColor = UIColor.clear.cgColor
        theView.layer.addSublayer(layer)
      }
    } else {
      cell.containerView.layer.borderColor = UIColor.lightGray.cgColor
      cell.containerView.layer.borderWidth = 0.5
      cell.containerView.layer.cornerRadius = 10
      cell.containerView.layer.masksToBounds = true
    }
  }
override func tableView(_ …Run Code Online (Sandbox Code Playgroud)