На основе представления NSTableView в Swift - Как
у меня естьNSTableView чьи клеткивид на основе.
DataSource & Delegate связаны, но яне удалось отобразить строковое значение textField ячейки.
Это код вObjective-C, работает:
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return 10;
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSTableCellView *cell = [tableView makeViewWithIdentifier:@"List" owner:self];
[cella.textField setStringValue:"Hey, this is a cell"];
return cell;
}
И вот мой код вСвифт, не работает :
func numberOfRowsInTableView(aTableView: NSTableView!) -> Int
{
return 10 //Casual number
}
func tableView(tableView: NSTableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> NSTableCellView! {
var cell = tableView.makeViewWithIdentifier("List", owner: self) as NSTableCellView!
// setup cell without force unwrapping it
cell.textField.stringValue = "Hey, this is a cell"
println("Method called") //Never printed
return cell
}
Это результат: (таблица на правой стороне изображения)
Обратите внимание, что комментарий//setup cell without force unwrapping it
нет смысла, я забыл удалить его.
Чего мне не хватает?
редактироватьЯ пробовал даже следующее безуспешно:
func numberOfRowsInTableView(aTableView: NSTableView!) -> Int
{
return 10
}
func tableView(tableView: NSTableView!, objectValueForTableColumn tableColumn: NSTableColumn!, row: Int) -> AnyObject
{
var cell = tableView.makeViewWithIdentifier("List", owner: self) as NSTableCellView
cell.textField.stringValue = "Hey this is a cell"
return cell;
}
Спасибо вам всем. Alberto