【发布时间】:2015-07-07 19:26:31
【问题描述】:
我有一个按钮可以在按下时更改另外两个按钮的文本。代码如下:
@IBAction func nextDay(sender: AnyObject) {
selectedDate = selectedDate.set("day", value: selectedDate.day + 1)!
//update button text
monthDayYearButton.setTitle(formatter.stringFromDate(selectedDate), forState: .Normal)
dayOfTheWeekButton.setTitle(selectedDate.weekdayName, forState: .Normal)
}
但是,只有 dayOfTheWeekButton 更改了它的标题。我知道这两个按钮之间的唯一区别是monthDayYearButton 使用属性文本而不是纯文本。我仅使用 Attributed Text 将字体设置为粗体。
我已经为每个状态按钮尝试过这个,包括 allZeros。
别担心我奇怪的 NSDate 操作,我安装了一个名为 SwiftDate 的可可豆荚。
【问题讨论】:
-
你能验证 'monthDayYearButton' 不是 nil 吗?确保它在情节提要中正确连接。
-
只需检查界面构建器中的按钮 IBOutlet 连接即可。