gpt4 book ai didi

ios - NSInternalInconsistencyException,在我关闭下一个场景后崩溃

转载 作者:行者123 更新时间:2023-11-30 12:27:14 25 4
gpt4 key购买 nike

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (10), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

我的应用程序在此页面崩溃

import UIKit
import MapKit
import CoreLocation

struct place {



}



class CourseClass: UITableViewController, CLLocationManagerDelegate, MKMapViewDelegate {


@IBOutlet weak var map: MKMapView!



var place = ["Caffè Spagar", "Duks", "Posta station", "Barnum", "Elephant Club", "Cinema", "Space", "Andromeda", "Rodolf", "Devil Chair"]
var rows = 0





override func viewDidLoad() {
super.viewDidLoad()

map.showsUserLocation = true
map.delegate = self
}



override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

insertRowsMode3()
}


func insertRowsMode2() {

for i in 0..<place.count {
insertRowMode2(ind: i, str: place[i])
}

}

func insertRowMode2(ind:Int,str:String) {

let indPath = IndexPath(row: ind, section: 0)

rows = ind + 1
tableView.insertRows(at: [indPath], with: .right)
}



func insertRowsMode3() {

rows = 0

insertRowMode3(ind: 0)
}




func insertRowMode3(ind:Int) {
let indPath = IndexPath(row: ind, section: 0)
rows = ind + 1
tableView.insertRows(at: [indPath], with: .right)


guard ind < place.count-1 else { return }
DispatchQueue.main.asyncAfter(deadline: .now()+0.15) {

self.insertRowMode3(ind: ind+1)
}
}











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

return 1
}


override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return rows
}



public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyTableViewCell

cell.myImage.image = UIImage(named: (place[indexPath.row] + ".png"))
cell.myLabel.text = place[indexPath.row]

return (cell)
}





override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

performSegue(withIdentifier: "goToLast" , sender: place[indexPath.row])

}


override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}





@IBAction func mapTapped(_ sender: Any) {

let userLocation = map.userLocation

let region = MKCoordinateRegionMakeWithDistance((userLocation.location?.coordinate)!,2000,2000)

map.setRegion(region, animated: true)
}







override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goToLast" {

guard let vc = segue.destination as? FinalClass else { return }

let guest = segue.destination as! FinalClass

guest.local = sender as! String

guest.localImage = UIImage(named: (sender as! String) + ".png")!

}
}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

在我关闭下一个 UIViewController 后;所以当我从上一个场景进入页面时,这是可以的,但是如果我之后继续进入场景,然后返回

 @IBAction func lastBack(_ sender: Any) {

dismiss(animated: true, completion: nil)
}

应用程序崩溃了,我该怎么办?

最佳答案

@Paulw11这是整个代码

import UIKit
import MapKit
import CoreLocation

struct place {



}



class CourseClass: UITableViewController, CLLocationManagerDelegate, MKMapViewDelegate {


@IBOutlet weak var map: MKMapView!



var place = ["Caffè Spagar", "Duks", "Posta station", "Barnum", "Elephant Club", "Cinema", "Space", "Andromeda", "Rodolf", "Devil Chair"]
var rows = 0





override func viewDidLoad() {
super.viewDidLoad()

map.showsUserLocation = true
map.delegate = self
}



override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

insertRowsMode3()
}


func insertRowsMode2() {

for i in 0..<place.count {
insertRowMode2(ind: i, str: place[i])
}

}

func insertRowMode2(ind:Int,str:String) {

let indPath = IndexPath(row: ind, section: 0)

rows = ind + 1
tableView.insertRows(at: [indPath], with: .right)
}



func insertRowsMode3() {

rows = 0

insertRowMode3(ind: 0)
}




func insertRowMode3(ind:Int) {
let indPath = IndexPath(row: ind, section: 0)
rows = ind + 1
tableView.insertRows(at: [indPath], with: .right)


guard ind < place.count-1 else { return }
DispatchQueue.main.asyncAfter(deadline: .now()+0.15) {

self.insertRowMode3(ind: ind+1)
}
}











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

return 1
}


override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return rows
}



public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyTableViewCell

cell.myImage.image = UIImage(named: (place[indexPath.row] + ".png"))
cell.myLabel.text = place[indexPath.row]

return (cell)
}





override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

performSegue(withIdentifier: "goToLast" , sender: place[indexPath.row])

}


override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}





@IBAction func mapTapped(_ sender: Any) {

let userLocation = map.userLocation

let region = MKCoordinateRegionMakeWithDistance((userLocation.location?.coordinate)!,2000,2000)

map.setRegion(region, animated: true)
}







override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goToLast" {

guard let vc = segue.destination as? FinalClass else { return }

let guest = segue.destination as! FinalClass

guest.local = sender as! String

guest.localImage = UIImage(named: (sender as! String) + ".png")!

}
}







override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

关于ios - NSInternalInconsistencyException,在我关闭下一个场景后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44043041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com