`func tableview (_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitebleviewcell {
let row = indexpath.row < /p>
Код: Выделить всё
let message = message(at: indexPath)
if message.role == Role.assistant.rawValue {
let chatCell = tableView.dequeueReusableCell(withIdentifier: ChatCell.identifier, for: indexPath) as! ChatCell
chatCell.formattingStackView.removeAllArrangedSubviews()
chatCell.index = row
chatCell.delegate = self
chatCell.text = message.content
if TentativeChatModel.shared.tentativeMessage.content != "" && row == TentativeChatModel.shared.chatList.count - 1 && message.role == Role.assistant.rawValue {
return chatCell
}
chatCell.configure(text: message.content)
if let reasoning = message.reasoningContent, let time = message.think_time, time >= 0 {
chatCell.collapseButton.isHidden = false
chatCell.reasoningView.isHidden = false
chatCell.thinkLabel.text = reasoning
chatCell.thoughtForLabel.text = "Thought for \(time)s"
if AppConstants.expandedRowIndex.contains(row) {
chatCell.reasoningView.borderWidth = 0.8
chatCell.thinkFooterView.isHidden = false
chatCell.chevronImageView.image = .chevronUp
} else {
chatCell.reasoningView.borderWidth = 0
chatCell.thinkFooterView.isHidden = true
chatCell.chevronImageView.image = .chevronUp
}
} else {
chatCell.reasoningView.isHidden = true
chatCell.collapseButton.isHidden = true
}
let document = Document(parsing: message.content)
let results = markdown.parserResults(from: document)
for result in results {
if result.isCodeBlock {
let spacer = UIView()
spacer.heightAnchor.constraint(equalToConstant: 10).isActive = true
let codeCell = try? CodeBlockView.view(with: self) as? CodeBlockView
codeCell?.translatesAutoresizingMaskIntoConstraints = false
codeCell?.codeLabel.attributedText = result.attributedString.trimmedTrailingNewlines()
codeCell?.languageLabel.text = result.codeBlockLanguage ?? "Output"
chatCell.formattingStackView.addArrangedSubview(codeCell!)
chatCell.formattingStackView.addArrangedSubview(spacer)
} else {
let label = UILabel()
label.attributedText = result.attributedString
label.textColor = .cLabel
label.translatesAutoresizingMaskIntoConstraints = false
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
chatCell.formattingStackView.addArrangedSubview(label)
}
}
if let citations = message.citations, !citations.isEmpty {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.heightAnchor.constraint(equalToConstant: 10).isActive = true
chatCell.formattingStackView.addArrangedSubview(view)
let collectionView = CitationsCollectionView(frame: .zero, collectionViewLayout: layoutForCitationsCollectionView())
collectionView.configure(citations)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.heightAnchor.constraint(equalToConstant: 180).isActive = true
collectionView.widthAnchor.constraint(equalToConstant: tableView.frame.width).isActive = true
chatCell.formattingStackView.addArrangedSubview(collectionView)
collectionView.onCitationTap = { [weak self] title, citation in
guard let self else { return }
customDelegate?.chatTableView(self, didTapCitation: citation, titleForCitation: title)
}
}
chatCell.streamLabel.isHidden = true
chatCell.formattingStackView.isHidden = false
return chatCell
} else {
let userCell = tableView.dequeueReusableCell(withIdentifier: UserCell.identifier, for: indexPath) as! UserCell
userCell.configure(message: message.content)
return userCell
}
}`
. Загрязняет и иногда застревает.
Что я подозреваю:
- Создание и настройка представлений в CellForrowat является тяжелой, а блокировка основной потоки. /> < /li>
Отсутствие повторного использования представлений для просмотров кодовых блоков внутри ячеек.
Чего я хочу достичь: < /strong> < /p>
< /li>
Плавное прокрутка, даже когда несколько кодовых блоков появляются внутри ячеек. дорогостоящее представление о создании на каждом прокрутке. < /p>
< /li>
< /ul>
Может ли кто -нибудь предложить лучшие практики или решения для эффективной обработки динамических подзоров, таких как пользовательские просмотры кодовых блоков внутри таблицы ячейки? ячейка.
Подробнее здесь: https://stackoverflow.com/questions/796 ... -scrolling
Мобильная версия