Я пробовал много способов исправить эту ошибку. Я относительно новичок в программировании для 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
Я пытаюсь составить таблицу, но постоянно получаю ошибки [закрыто] ⇐ IOS
Программируем под IOS
-
Anonymous
1726525255
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)
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78986511/i-am-trying-to-make-a-table-but-i-keep-getting-errors[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия