是否可以将Tableview“包装”单元格转换为新列?

时间:2013-10-15 01:20:29

标签: objective-c macos cocoa nstableview

我有一个标准的单列NSTableView,其设置如下:

1
2
3
4
5
6
7
8
9

是否可以水平显示数据,然后像这样包装?

1 2 3
4 5 6
7 8 9

或者我不应该完全使用NSTableView吗?我试图避免使用广泛的逻辑来做到这一点。

1 个答案:

答案 0 :(得分:1)

嗯,你可以这样做,但直接没有这样的api使它水平。您必须获取三列,然后将第一行数据插入三列。插入3列数据后,您必须开始填写下一行,就像您可以在表视图上实现的逻辑一样。另外如何实现同样的方法是将一个数组添加到数组中的上述数字1-9然后运行内部循环,每3个值采用可变字典,一旦插入三个数据就开始将数据放入行中开始填充相同的数据到下一行。 下面是您需要执行的小代码和绑定: -

        1)Drag and drop arraycontroller 
        now go to binding inspector and see the binding in the screen shot attached:-
        ![enter image description here][1]


      [1]: http://i.stack.imgur.com/1dcDy.png

2) Now in your table view select first column and do the binding in attached screen shot
![enter image description here][2]
![enter image description here][3]


3) similarly do for second and third column with name inside model key path for second column give name second and for third column give third.

4) Once binding has done.
Write the below code in your method where you required:

-(void)awakeFromNib
{
    int i,j=1,k=2,l=3;
    self.yourArray=[NSMutableArray array];
    for (i=0; i<3;i++)
        {        
        NSMutableDictionary *dc=[NSMutableDictionary dictionary];
        [dc setObject:[NSNumber numberWithInt:j] forKey:@"first"];
        [dc setObject:[NSNumber numberWithInt:k] forKey:@"second"];
        [dc setObject:[NSNumber numberWithInt:l] forKey:@"third"];
        [self.yourArray addObject:dc];
        [self setYourArray:self.yourArray];
        j=j+3;
        k=k+3;
        l=l+3;
    }
}


  [1]: http://i.stack.imgur.com/6cm6M.png
  [2]: http://i.stack.imgur.com/6cm6M.png
  [3]: http://i.stack.imgur.com/51oET.png