Я пытаюсь составить таблицу, но постоянно получаю ошибки [закрыто]IOS

Программируем под IOS
Ответить
Anonymous
 Я пытаюсь составить таблицу, но постоянно получаю ошибки [закрыто]

Сообщение Anonymous »

Я пробовал много способов исправить эту ошибку. Я относительно новичок в программировании для iOS.
Это ошибка, которую я постоянно получаю

(Неверное обновление: неверное количество Количество разделов, содержащихся в табличном представлении после обновления (1), должно быть равно количеству разделов, содержащихся в табличном представлении до обновления (0), плюс или минус количество вставленных или удаленных разделов (0 вставлено). , 0 удалено). имя = tableBackgroundColor> Layer = ; contentOffset: {0, -59}; contentSize: {393, 44}; ")

Код для создания таблицы приведен ниже.
import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }

let itemStore = ItemStore()

let itemController = window!.rootViewController as! ItemsViewController

itemController.itemStore = itemStore
}


import UIKit

class Item: Equatable {
var name: String
var valueInDollars: Int
var serialNumber: String?
var dateCreated: Date

init(name: String, serialNumber: String?, valueInDollars: Int) {
self.name = name
self.valueInDollars = valueInDollars
self.serialNumber = serialNumber
self.dateCreated = Date()
}

convenience init(random: Bool = false) {
if random {
let adjectives = ["Fluffy", "Rusty", "Shiny"]
let nouns = ["Bear", "Spork", "Mac"]

let randomAdjectives = adjectives.randomElement()!
let randomNoun = nouns.randomElement()!

let randomName = "\(randomAdjectives) \(randomNoun)"
let randomValue = Int.random(in: 0.. Bool {
return lhs.name == rhs.name && lhs.serialNumber == rhs.serialNumber && lhs.valueInDollars == rhs.valueInDollars && lhs.dateCreated == rhs.dateCreated
}

}

class ItemStore {

var allItems = [Item]()
@discardableResult func createItem() -> Item {
let newItem = Item(random: true)

allItems.append(newItem)

return newItem
}

func removeItem(_ item: Item) {
if let index = allItems.firstIndex(of: item) {
allItems.remove(at: index)
}
}

func moveItem (from fromIndex: Int, to toIndex: Int) {
if fromIndex == toIndex {
return
}

let movedItem = allItems[fromIndex]

allItems.remove(at: fromIndex)

allItems.insert(movedItem, at: toIndex)
}
/*
init() {
for _ in 0.. Int {
// #warning Incomplete implementation, return the number of sections
return itemStore.allItems.count
}

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

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// #warning Incomplete implementation, return the number of rows
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)

let item = itemStore.allItems[indexPath.row]

cell.textLabel?.text = item.name
cell.detailTextLabel?.text = "\(item.valueInDollars)"

return cell
}

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let item = itemStore.allItems[indexPath.row]
itemStore.removeItem(item)
tableView.deleteRows(at: [indexPath], with: .automatic)
}
}

override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
itemStore.moveItem(from: sourceIndexPath.row, to: destinationIndexPath.row)
}

}



Подробнее здесь: https://stackoverflow.com/questions/789 ... ing-errors
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»