【发布时间】:2021-12-20 11:14:48
【问题描述】:
我正在为一个班级构建一个 iOS 应用程序,并且我正在按照一些说明进行操作。编辑按钮连接到toggleEditingMode,但是当我更改文本时,由于某种原因字体大小被重置为17,即使它在故事板编辑器中是30。
我尝试过更改字体大小,如果我在执行 setTitle 后打印当前字体大小,它仍然显示 30,所以它似乎必须在 setTitle 之外发生,但它只有在我使用 setTitle 时才会触发。救命!
class ItemsViewController: UITableViewController {
var choreStore: ChoreStore!
var roommateStore: RoommateStore!
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return choreStore.allChores.count
}
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Create an instance of UITableViewCell with default appearance
let cell = tableView.dequeueReusableCell(withIdentifier: "chore", for: indexPath) as! ChoreCell
// Set the text on the cell with the description of the item
// that is at the nth index of items, where n = row this cell
// will appear in on the table view
let chore = choreStore.allChores[indexPath.row]
cell.title?.text = chore.title
cell.turn?.text = "\(chore.whoseTurn())'s Turn"
cell.completed?.text = chore.completedString()
cell.completed?.textColor = chore.isOverdue ? .red : .black
return cell
}
@IBAction func addNewItem(_ sender: UIButton) {
}
@IBAction func toggleEditingMode(_ sender: UIButton) {
setEditing(!isEditing, animated: true)
sender.setTitle(isEditing ? "Done" : "Edit", for: .normal)
}
}
【问题讨论】:
-
我也有同样的问题。你能解决吗?