【发布时间】:2020-10-02 21:52:46
【问题描述】:
我在 tableView 单元格中有一个 UILabel,我想逐行制作动画。该字符串有换行符,\n 和lines.count 按预期返回 7,但即使字符串本身不是 nil,也没有任何行被添加到标签中。
cellForRow 中的代码
var index = 0
let lines = messageList[indexPath.row].message.components(separatedBy: "\n")
senderCell.otherUserMessage.numberOfLines = lines.count
Timer.scheduledTimer(withTimeInterval: 3, repeats: true, block: { [weak self] timer in
if index != lines.count {
let char = lines[index]
let nChar = "\n\(char)"
senderCell.otherUserMessage.text! += nChar
print("char is \(nChar)") //nChar prints the proper text
print("senderCellText is \(senderCell.otherUserMessage.text!)") // but this prints an array of numbers
// Play sound each time
do {
self!.audioPlayer = try AVAudioPlayer(contentsOf: self!.koalaMessageSound)
self!.audioPlayer.play()
}catch{
// couldn't load file :(
}
index += 1
} else {
timer.invalidate()
}
})
【问题讨论】:
-
没有动画能用吗?你有
senderCell.otherUserMessagel.numberOfLines = 0;吗? -
谢谢@danh。是的,我有
senderCell.otherUserMessage.numberOfLines = lines.count我现在将其添加到问题中。 -
@Dekpe 这不直观,但您希望将 numberOfLines 设置为 0。
标签: ios swift uitableview animation uilabel