1

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

1
2
3
4
5
6
7
8
9

是否可以让数据水平显示,然后像这样换行?

1 2 3
4 5 6
7 8 9

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

4

1 回答 1

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
于 2013-10-15T02:01:08.150 回答