附加CellType索引范围错误误差swift
在附加新的CellType后,我的位置TableViewCell在输入文本字段搜索栏内输入文本时,在Let plote = place = place = place = place = place = place = place = place = place = place = place = place = place = place place = place = ploteviewcell之后。
private func locationTableViewCell(indexPath: IndexPath) -> PostSelectLocationTableViewCell {
let locationCell = tableView.dequeueReusableCell(forIndexPath: indexPath) as PostSelectLocationTableViewCell
let place = places[indexPath.row]
locationCell.configure(model: place)
return locationCell
}
locationInteractor.didPlacesLoaded = { [weak self] places in
DispatchQueue.main.async {
self?.places = places
if self?.places.isEmpty == true {
self?.cellTypes = [.empty]
} else {
self?.cellTypes += Array(repeating: .location, count: self?.places.count ?? 0)
}
self?.tableView.reloadData()
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cellTypes.count
}
在添加。含量之前,一切都是桃子。但是现在,当我输入在位置之间搜索的文本时,它会以索引不超出范围错误崩溃。我试图让plote = plote [indexpath.row + 1],让plote = plote = plote [indexpath.row -1],但无效。
locationInteractor.didCurrrentPlaceLoaded = { [weak self] currentPlace in
self?.currentLocation = currentPlace
self?.cellTypes.append(.currentLocation)
self?.tableView.reloadData()
}
After appending a new cellType my locationTableViewCell is giving an error at let place = places[indexPath.row] while entering text inside the text field search bar.
private func locationTableViewCell(indexPath: IndexPath) -> PostSelectLocationTableViewCell {
let locationCell = tableView.dequeueReusableCell(forIndexPath: indexPath) as PostSelectLocationTableViewCell
let place = places[indexPath.row]
locationCell.configure(model: place)
return locationCell
}
locationInteractor.didPlacesLoaded = { [weak self] places in
DispatchQueue.main.async {
self?.places = places
if self?.places.isEmpty == true {
self?.cellTypes = [.empty]
} else {
self?.cellTypes += Array(repeating: .location, count: self?.places.count ?? 0)
}
self?.tableView.reloadData()
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cellTypes.count
}
before appending .currentLocation everything was peachy. But now when I enter a text to search between locations, it crashes with Index Out Of Range error. I have tried to let place = places[indexPath.row + 1] and let place = places[indexPath.row - 1] but it was ineffective.
locationInteractor.didCurrrentPlaceLoaded = { [weak self] currentPlace in
self?.currentLocation = currentPlace
self?.cellTypes.append(.currentLocation)
self?.tableView.reloadData()
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于我以前的数字如下。
因此,这导致我索引外部错误。
在更改NumberRowsInsection之后,对于每个特定的CellType,我的错误就消失了。
The problem was that my previous numberOfRowsInSection was as below.
so this was causing me index out-of-range error.
After changing numberOfRowsInSection as below for each specific celltype my error is gone.