Ошибка выполнения Swift: «Не удается завершить BackgroundTask: фоновая задача с идентификатором 1 не существует» - PullRequest
1 голос
/ 01 ноября 2019

Я пытаюсь реализовать пример TableView из главы 5 Быстрое программирование в упражнении Easy Steps . Я проверил и перепроверил пример кода (даже скачал и протестировал пример кода), но я все еще получаю эту ошибку времени выполнения. Кто-нибудь знает, почему это происходит?

2019-11-01 07: 56: 51.247052 + 0100 TableView_EasySteps [2067: 39485] Не удается завершить BackgroundTask: не существует фоновой задачи с идентификатором 1 (0x1), или это, возможно, уже закончилось. Перерыв в UIApplicationEndBackgroundTaskError () для отладки.

вот код ViewController:

import UIKit

class WebsitesTableViewController: UITableViewController {

    var websites:[[String]] = [
        ["Apple",           "https://www.apple.com"]   ,
        ["NY Times",        "https://www.nytimes.com"] ,
        ["DN",              "https://www.dn.se"]   ,
        ["NFL",             "https://www.nfl.com"]   ,
        ["Premier League",  "https://www.premierleague.com"]   ,
        ["The Guardian",    "https://www.theguardian.com"]
    ]

    override func viewDidLoad() {
        super.viewDidLoad()

        // preserve selection between presentations
        self.clearsSelectionOnViewWillAppear = false
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return websites.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier")
        if cell == nil {
            cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cellIdentifier")
        }
        cell!.textLabel!.text = websites[indexPath.row][0]
        cell!.detailTextLabel!.text = websites[indexPath.row][1]

        return cell!
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let url = URL(string: websites[indexPath.row][1]) {
            UIApplication.shared.open(url)
        }
    }

    // Override to support editing the table view.
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            websites.remove(at: indexPath.row)
            // Delete the row from the data source
            tableView.deleteRows(at: [indexPath], with: .fade)
        }
    }
}
...