我有一个UITableView(iOS 9),我通过滑动实现了两个操作(一个是删除操作),我有一个“编辑”按钮以启用编辑模式(对行进行重新排序)
为此,我实施了
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated:animated)
if (!isInSwipeDeleteMode) {
if (self.tableView.editing) {
metAJourPersonnes()
tableView.reloadData()
}
else {
tableView.reloadData()
}
}
}
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
if (indexPath.row < personnes.count) {
return true
} else {
return false
}
}
override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
let pers = personnes[sourceIndexPath.row]
personnes.removeAtIndex(sourceIndexPath.row)
if (destinationIndexPath.row < personnes.count)
{
personnes.insert(pers, atIndex: destinationIndexPath.row)
} else {
personnes.append(pers)
} …
Run Code Online (Sandbox Code Playgroud) 我有一个用Swift编写的工作音乐应用程序.我想整合睡眠模式,可以暂停播放的音乐,例如10分钟.我用perform(_ aSelector: Selector, with anArgument: Any?, afterDelay delay: TimeInterval)
这个任务,它工作得很好.
但是有一个问题.iPhone很有可能在10分钟结束前进入睡眠状态,因此不会调用暂停功能,音乐会继续播放.
我知道还有其他方法可以在10分钟后发送一个动作(NSTimer,使用GCD)但是如果我理解,这些解决方案都不会阻止机器进入睡眠状态,或者唤醒应用程序来执行任务.
也许我可以使用后台模式,但是:
这是实现我需要的方式吗?