0

This code compiles OK, but the ComboBox (cbxColors) is empty - not populated from the Data Source (array: COLORS_OF). Uses Data Source is checked in IB.

func numberOfItemsInComboBox() returns the correct result: 5.

func comboBox() is not doing its job.

What am I missing?

EDITED: Now working.

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSComboBoxDelegate, NSComboBoxDataSource {

@IBOutlet weak var window: NSWindow!


func applicationDidFinishLaunching(aNotification: NSNotification) {

    cbxColors.dataSource = self

    numberOfItemsInComboBoxCell(cbxColors)
    comboBoxCell(cbxColors, objectValueForItemAtIndex: 0)
}

func applicationWillTerminate(aNotification: NSNotification) {

}

@IBOutlet weak var cbxColors: NSComboBox!
@IBOutlet weak var txtResult: NSTextField!


@IBAction func actColors(sender: NSComboBox) {
    // display User selected item in 'txtResult'
}

func numberOfItemsInComboBoxCell(aComboBox: NSComboBox) -> Int {
    return(COLORS_OF.count)
}

func comboBoxCell(aComboBox: NSComboBox, objectValueForItemAtIndex index: Int) -> AnyObject {
    return(COLORS_OF[index])
}

let COLORS_OF = [ "Blue", "Green", "Purple", "Red", "Yellow" ]
} 
4

1 に答える 1

1

Uses Data Source をチェックするのを忘れたか、データソース接続を削除して再接続する必要があります (Xcode の奇妙なバグ)。

ここに画像の説明を入力

それ以外は、アウトレットが正しくフックされていれば、コードが機能します。

ここに画像の説明を入力

于 2015-10-06T14:32:20.837 に答える