小编Fre*_*icP的帖子

允许UITableView重新排序,但不允许在编辑模式下删除,并且无论如何都允许滑动以删除

我有一个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)

uitableview ios

5
推荐指数
1
解决办法
1817
查看次数

如何防止应用程序进入睡眠状态,以便为音乐集成睡眠模式

我有一个用Swift编写的工作音乐应用程序.我想整合睡眠模式,可以暂停播放的音乐,例如10分钟.我用perform(_ aSelector: Selector, with anArgument: Any?, afterDelay delay: TimeInterval)这个任务,它工作得很好.

但是有一个问题.iPhone很有可能在10分钟结束前进入睡眠状态,因此不会调用暂停功能,音乐会继续播放.

我知道还有其他方法可以在10分钟后发送一个动作(NSTimer,使用GCD)但是如果我理解,这些解决方案都不会阻止机器进入睡眠状态,或者唤醒应用程序来执行任务.

也许我可以使用后台模式,但是:

  1. 我的目标不是真正解决这种模式应该解决的问题.我不想有时间完成,我只想在某个时间使用1/10的第二个处理器.
  2. 此选项不保证在10分钟内工作.

这是实现我需要的方式吗?

timer background-process ios swift sleep-mode

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

标签 统计

ios ×2

background-process ×1

sleep-mode ×1

swift ×1

timer ×1

uitableview ×1