【发布时间】:2018-06-04 15:34:06
【问题描述】:
我有一个带有多个 UITableviews 的视图控制器。我想在从 tableview 中删除一行时删除与该行关联的通知,这是我的代码,但我收到错误 Index out of range 如果有人想测试它,这是我的项目的链接:https://files.fm/f/nwx8e7je
我的代码:它可以在没有简单字符串的情况下工作,但使用索引行时出现错误。
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
if tableView == ScheduleTableView{
let defaults = UserDefaults.standard
var myarray = defaults.stringArray(forKey: "ScheduleArray") ?? [String]()
var myarray2 = defaults.stringArray(forKey: "ScheduleTimeArray") ?? [String]()
// Remove Row
myarray.remove(at: indexPath.row)
myarray2.remove(at: indexPath.row)
defaults.set(myarray, forKey: "ScheduleArray")
defaults.set(myarray2, forKey: "ScheduleTimeArray")
ScheduleTableView.deleteRows(at: [indexPath], with: .fade)
UserDefaults.standard.synchronize()
// Remove Notification
let center = UNUserNotificationCenter.current()
let arrayToSearch = myarray[indexPath.row] as String
center.getPendingNotificationRequests { (notifications) in
for item in notifications {
if(item.identifier.contains(arrayToSearch)) {
center.removePendingNotificationRequests(withIdentifiers: [item.identifier])
}
}
}
}
if tableView == GoalsTableView{
}
}
【问题讨论】:
标签: ios swift uitableview push-notification uilocalnotification