Я использую 2 пользовательских класса, которые наследуют uicollectionView. Оба показывают аналогичную ошибку всех элементов в представлении коллекции, показывают последний элемент в массиве исходных источников.class ClothingVC: UICollectionViewController {
let clothesList = [
Garment(itemID: 0, itemName: "Orange shirt 0", cost: 0, isOwned: true, image: UIImage(named: "placeholdershirt")!),
Garment(itemID: 1, itemName: "Skirt 1", cost: 0, isOwned: true, image: UIImage(named: "skirt1")!),
Garment(itemID: 2, itemName: "Skirt 2", cost: 0, isOwned: true, image: UIImage(named: "skirt2")!)
]
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return clothesList.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let clotheslistItem: Garment = clothesList[indexPath.count]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "clothesCell", for: indexPath) as? ClothesCell
cell?.image.image = clotheslistItem.image
cell?.label.text = clotheslistItem.itemName
return cell!
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
@IBOutlet weak var clothesViewGrid: ClothesView!
override func viewDidLoad() {
super.viewDidLoad()
clothesViewGrid.reloadData()
}
}
< /code>
'' '< /p>
Позже у меня есть другой файл. Он продолжал высказываться, говоря об индексе за пределами границ, поэтому я добавил -1, чтобы остановить сбой, я знаю, что его не должно быть, но я также не знаю, почему у него проблемы с индексом. На этом VC показывает 3 ячейки, все названные Бетти. Я думаю, что единственная причина, по которой это не показывает, было то, что я добавил -с. 1. < /P>
class ProfileSelectorVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{
let profiles = [
KidProfile(accountType: AccountType.child, name: "Amy", birthday: NSDate(), profilePicture: UIImage(named: "Panda_Ears")!, age: 10, pets: [], petBirthday: NSDate(), clothesInventory: [], allTimePoints: 0, currentPoints: 0, optionalSoundEffects: false),
KidProfile(accountType: AccountType.child, name: "Betty", birthday: NSDate(), profilePicture: UIImage(named: "Monkey_Ears")!, age: 10, pets: [], petBirthday: NSDate(), clothesInventory: [], allTimePoints: 0, currentPoints: 0, optionalSoundEffects: false),
KidProfile(accountType: AccountType.child, name: "Caty", birthday: NSDate(), profilePicture: UIImage(named: "Pig_Ears")!, age: 10, pets: [], petBirthday: NSDate(), clothesInventory: [], allTimePoints: 0, currentPoints: 0, optionalSoundEffects: false)
]
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return profiles.count
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let profile: Profile = profiles[indexPath.count-1]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "profilesReuseIdentifier", for: indexPath) as? ProfileCell
cell?.profileName.text = profile.name
cell?.profilePicture.image = profile.profilePicture
//cell?.profileName
return cell!
}
@IBOutlet weak var profilesOutlet: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
profilesOutlet.reloadData()
}
}
< /code>
Почему все мои представления Uicollection просто показывают повторное содержание последней ячейки? Что не так с моим кодом? Также o Я продолжаю наносить проблемы индекса с профилями VC, когда у меня нет -1? Введите описание изображения здесь
Подробнее здесь: https://stackoverflow.com/questions/796 ... array-entr
Почему мои UICollectionViews все показывают одни и те же данные ячейки (последняя запись в массиве)? ⇐ IOS
Программируем под IOS
1751741142
Anonymous
Я использую 2 пользовательских класса, которые наследуют uicollectionView. Оба показывают аналогичную ошибку всех элементов в представлении коллекции, показывают последний элемент в массиве исходных источников.class ClothingVC: UICollectionViewController {
let clothesList = [
Garment(itemID: 0, itemName: "Orange shirt 0", cost: 0, isOwned: true, image: UIImage(named: "placeholdershirt")!),
Garment(itemID: 1, itemName: "Skirt 1", cost: 0, isOwned: true, image: UIImage(named: "skirt1")!),
Garment(itemID: 2, itemName: "Skirt 2", cost: 0, isOwned: true, image: UIImage(named: "skirt2")!)
]
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return clothesList.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let clotheslistItem: Garment = clothesList[indexPath.count]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "clothesCell", for: indexPath) as? ClothesCell
cell?.image.image = clotheslistItem.image
cell?.label.text = clotheslistItem.itemName
return cell!
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
@IBOutlet weak var clothesViewGrid: ClothesView!
override func viewDidLoad() {
super.viewDidLoad()
clothesViewGrid.reloadData()
}
}
< /code>
'' '< /p>
Позже у меня есть другой файл. Он продолжал высказываться, говоря об индексе за пределами границ, поэтому я добавил -1, чтобы остановить сбой, я знаю, что его не должно быть, но я также не знаю, почему у него проблемы с индексом. На этом VC показывает 3 ячейки, все названные Бетти. Я думаю, что единственная причина, по которой это не показывает, было то, что я добавил -с. 1. < /P>
class ProfileSelectorVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{
let profiles = [
KidProfile(accountType: AccountType.child, name: "Amy", birthday: NSDate(), profilePicture: UIImage(named: "Panda_Ears")!, age: 10, pets: [], petBirthday: NSDate(), clothesInventory: [], allTimePoints: 0, currentPoints: 0, optionalSoundEffects: false),
KidProfile(accountType: AccountType.child, name: "Betty", birthday: NSDate(), profilePicture: UIImage(named: "Monkey_Ears")!, age: 10, pets: [], petBirthday: NSDate(), clothesInventory: [], allTimePoints: 0, currentPoints: 0, optionalSoundEffects: false),
KidProfile(accountType: AccountType.child, name: "Caty", birthday: NSDate(), profilePicture: UIImage(named: "Pig_Ears")!, age: 10, pets: [], petBirthday: NSDate(), clothesInventory: [], allTimePoints: 0, currentPoints: 0, optionalSoundEffects: false)
]
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return profiles.count
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let profile: Profile = profiles[indexPath.count-1]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "profilesReuseIdentifier", for: indexPath) as? ProfileCell
cell?.profileName.text = profile.name
cell?.profilePicture.image = profile.profilePicture
//cell?.profileName
return cell!
}
@IBOutlet weak var profilesOutlet: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
profilesOutlet.reloadData()
}
}
< /code>
Почему все мои представления Uicollection просто показывают повторное содержание последней ячейки? Что не так с моим кодом? Также o Я продолжаю наносить проблемы индекса с профилями VC, когда у меня нет -1? Введите описание изображения здесь
Подробнее здесь: [url]https://stackoverflow.com/questions/79691260/why-are-my-uicollectionviews-all-showing-the-same-cell-data-the-last-array-entr[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия