【发布时间】:2014-11-12 02:00:31
【问题描述】:
以下代码将更改所有 3 个组件的选取器视图的字体颜色。但是,当我尝试旋转车轮时它会崩溃。我认为这与 didSelectRow 函数有关。也许这两个函数必须以某种方式嵌套?有什么想法吗?
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
var attributedString: NSAttributedString!
if component == 0 {
attributedString = NSAttributedString(string: a.text!, attributes: [NSForegroundColorAttributeName : UIColor.redColor()])
}
if component == 1 {
attributedString = NSAttributedString(string: b.text!, attributes: [NSForegroundColorAttributeName : UIColor.redColor()])
}
if component == 2 {
attributedString = NSAttributedString(string: c.text!, attributes: [NSForegroundColorAttributeName : UIColor.redColor()])
}
return attributedString
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int){
switch component {
case 0:
aOutput.text = a[row] --> **Code breaks**
case 1:
bOutput.text = b[row]
case 2:
cOutput.text = c[row]
default:
10
}
【问题讨论】:
-
你有没有尝试过?在提问之前,您应该尝试并做出一些努力。
-
是的,当然,花费数小时和数小时,参加了 2 门课程 - 从零开始,在没有编程背景的情况下不间断地在这个应用程序上工作了一周。但这很难,所有的教程都在操场上。因此,虽然我的逻辑是正确的,但我无法理解代码在哪里。 swift/object C的所有初始化(我认为它被调用)和范围。
-
和范围。如果您不了解诸如“var mySpeechSynthesizer: AVSpeechsynthesizer...”之类的语句是什么,它的去向以及调用它们的顺序以及什么,那么知道如何在 Playground 中编写 switch/case 语句也无济于事打电话给他们。我什至不知道我不知道的东西的名字......大声笑你怎么不问就知道这样的东西,告诉我,因为我在电子书、课程或 Youtube 上找不到它
标签: ios xcode swift uipickerview xcode6gm