Swift中基于视图的NSTableView-如何 [英] View-Based NSTableView in Swift - How to
本文介绍了Swift中基于视图的NSTableView-如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 NSTableView ,其单元格基于基于视图。
I have a NSTableView whose cells are view-based.
DataSource&委托已连接,但我无法显示单元格的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;
}
这是我在 Swift中无法运行的代码 >:
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
}
这是结果:(图像的右侧)
This is the result: (table on right side of image)
请注意,注释 // setup单元没有强制展开即可
没有任何意义,我忘了删除它。
Note that the comment //setup cell without force unwrapping it
makes no sense, I forgot to delete it.
编辑 :我什至尝试了以下操作,但均未成功:
Edit: I tried even the following with no success:
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
Thank you all. Alberto
推荐答案
经过数小时的搜索,我发现这种方法有效!
After hours of search, I discovered this method that works !
func tableView(tableView: NSTableView, viewForTableColumn: NSTableColumn, row: Int) -> NSView
{
var cell = tableView.makeViewWithIdentifier("List", owner: self) as NSTableCellView
cell.textField.stringValue = "Hey, this is a cell"
return cell;
}
这篇关于Swift中基于视图的NSTableView-如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文