小编Mat*_*ler的帖子

无法将数据从 NSUserDefaults 检索到今天的扩展 (Swift)

我有一组数组,它​​们都包含我创建的自定义 Task 对象的多个实例。我将数组保存到 NSUserDefaults 如下:

自定义任务对象

class Task:NSObject, NSCoding {
    var name:String
    var notes:String
    var date:NSDate
    var dateUse:Bool
    var taskCompleted:Bool

    init(name:String, notes:String, date:NSDate, dateUse:Bool, taskCompleted:Bool){
        self.name = name
        self.notes = notes
        self.date = date
        self.dateUse = dateUse
        self.taskCompleted = taskCompleted
    }

    required init(coder decoder: NSCoder){
        self.name = decoder.decodeObjectForKey("name") as! String
        self.notes = decoder.decodeObjectForKey("notes") as! String
        self.date = decoder.decodeObjectForKey("date") as! NSDate
        self.dateUse = decoder.decodeObjectForKey("dateUse") as! Bool
        self.taskCompleted = decoder.decodeObjectForKey("taskCompleted") as! Bool
    }

    func encodeWithCoder(coder: NSCoder) {
        coder.encodeObject(self.name, forKey: "name")
        coder.encodeObject(self.notes, forKey: …
Run Code Online (Sandbox Code Playgroud)

nsuserdefaults ios swift today-extension

4
推荐指数
1
解决办法
1061
查看次数

自定义 UITableViewCell 为空(Swift)

我正在尝试在 Swift 中设置自定义 UITableViewCell。我还创建了 XIB 文件和 swift 文件。但是,当我运行应用程序时,单元格不会填充我的自定义单元格,而是一个完全空白的单元格。

我已将我的手机注册到:

self.myTableView.registerClass(customCell.self, forCellReuseIdentifier: "cell")
Run Code Online (Sandbox Code Playgroud)

我还设置了以下内容:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
   return 3
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
   let cell = myTableView.dequeueReusableCellWithIdentifier("cell") as! customCell
   cell.descriptionLabel.text = "test"
   return cell
}
Run Code Online (Sandbox Code Playgroud)

此外,我还在自定义单元格中设置了一个指向 UILabel 的链接。当我尝试更新它时,应用程序崩溃了。该线cell.descriptionLabel.text = "test"如上图所示。

uitableview ios swift

4
推荐指数
1
解决办法
1081
查看次数

本地通知发出声音但不显示(Swift)

我正在尝试使用Apple的UNUserNotificationCenter为我的应用创建本地通知.

这是我的代码:

let center = UNUserNotificationCenter.current()

let content = UNMutableNotificationContent()
content.title = task.name
content.body = task.notes
content.sound = UNNotificationSound.default()

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)

let request = UNNotificationRequest(identifier: task.UUID, content: content, trigger: trigger)

center.add(request) { (error:Error?) in
   if let theError = error {
      print("Notification scheduling error: \(error)")
   }else{
      print("Notification was scheduled successfully")
   }
}
Run Code Online (Sandbox Code Playgroud)

访问请求:

let center = UNUserNotificationCenter.current()

//request notification access
let options: UNAuthorizationOptions = [.alert, .sound]
center.requestAuthorization(options: options) { (granted, error) in
   if !granted {
      print("Notification …
Run Code Online (Sandbox Code Playgroud)

ios swift unnotificationrequest

4
推荐指数
1
解决办法
2448
查看次数

更新Firebase中的现有数据(Swift)

Firebase数据结构:

users
       - 90384m590v834dfgok34
          •userName: "Matt"
          •values: ["test1", "test2"]
Run Code Online (Sandbox Code Playgroud)

我想更新这些firebase条目中的值而不替换整个事情.我知道update()函数是我需要做的,但是从我尝试过的例子来看它不起作用.

另外,如何通过update()函数将新项添加到values数组?

firebase swift firebase-realtime-database

2
推荐指数
1
解决办法
7103
查看次数