我应该将水平上方图像中的三角形翻转,使斜边位于左侧,而不是右侧。我已经尝试了很长时间,似乎无法弄明白。
答案 0 :(得分:2)
我想你只想要你得到的输出镜像。请尝试以下代码;
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let answerCell = tableView.dequeueReusableCell(withIdentifier: "AnswerCell") as! AnswerCell
// action added to button
answerCell.likeButtonClicked.addTarget(self, action: #selector(likeButtonClicked), for: .touchUpInside)
// updated set tag to button
answerCell.likeButtonClicked.tag = indexPath.row
let answer = answers[indexPath.row]
answerCell.answerText.text = answer.answerText
answerCell.username.text = "~ \(answer.username)"
answerCell.numberOfLikes.text = "\(answer.numberOflikes) liked this answer."
answerCell.answerText.numberOfLines = 0
return answerCell
}
输出:
@IBAction func likeButtonClicked(_ sender: UIButton) {
//updated now tag is row position of button in cell and is equal to (indexPath.row) of that particular button.tag is equal to
let tag = sender.tag
// here indexPath.row can be replace by tag so
//let answer = answers[indexPath.row] == let answer = answers[tag]
// updated till here
ref = Database.database().reference()
ref.child("answerLikes").child((answer.id).observeSingleEvent(of: .value, with: {
(snapshot) in
if let _ = snapshot.value as? NSNull {
sender.setImage(UIImage(named: "filledHeart.png"), for: .normal)
} else {
answerLikes = [Auth.auth().currentUser?.uid : true]
ref.child("answerLikes").child(answer.id).updateChildValues(answerLikes)
sender.setImage(UIImage(named: "emptyHeart.png"), for: .normal)
}
})
}
答案 1 :(得分:1)
一种简单的方法,保留您已有的代码,将使用格式规范来填充和右对齐输出:
total = 0
x = range(1, 8)
for i in x:
total = 'T' * i
print("{:>8}".format(total), end='\n\n')
值得花一点时间来学习print()
和str.format()
可以执行的各种转换:
> python3 test.py
T
TT
TTT
TTTT
TTTTT
TTTTTT
TTTTTTT
>