NSTableView 高度调整
我正在使用 NSTableView 来显示我的数据。我必须通过单击一些按钮来更改表数据。所以行数不固定。有时仅使用 2 行,有时仅使用 12 行。
当只需要 2 行时,表格看起来不太好。
我想要的是我的表格视图高度可以根据使用的行数或单元格数调整大小。
我尝试了这个,但它对我不起作用..感染我什至看不到我的表使用该代码。 我正在使用 NSWindowController。
编辑:
- (void)addImageToTableView
{
[tableView setBackgroundColor:[NSColor clearColor]];
[tableView setHeaderView:nil];
if([title isEqualToString:@"First"]){
if ([[arrayController arrangedObjects] count] != 0)
{
[arrayController removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[arrayController arrangedObjects ] count])]];
}
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"MS.png"],@"image", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"CVS.png"],@"image", nil]];
}
if ([title isEqualToString:@"Second"]) {
if ([[arrayController arrangedObjects] count] != 0)
{
[arrayController removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[arrayController arrangedObjects ] count])]];
}
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"NS.png"],@"image", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"EM.png"],@"image", nil]] ;
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"RES.png"],@"image", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"ERS.png"],@"image", nil]] ;
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"RS.png"],@"image", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"FB.png"],@"image", nil]] ;
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"SKIN.png"],@"image", nil]];
}
[tableView reloadData];
[self windowDidLoad];
}
-(void)windowDidLoad{
[super windowDidLoad];
}
还有其他建议吗??
提前致谢..!!
I am using NSTableView
to display my data. I have to change table data by clicking some buttons. So number of rows are not fix. Sometime it use only 2 rows and sometimes 12.
When it takes only 2 rows then table looks not good.
What i want is my tableview height can be resize according to number of rows or cell used.
I tried this but its not working with me.. Infect i can't even see my table by using that code.
I am using NSWindowController
.
EDIT :
- (void)addImageToTableView
{
[tableView setBackgroundColor:[NSColor clearColor]];
[tableView setHeaderView:nil];
if([title isEqualToString:@"First"]){
if ([[arrayController arrangedObjects] count] != 0)
{
[arrayController removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[arrayController arrangedObjects ] count])]];
}
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"MS.png"],@"image", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"CVS.png"],@"image", nil]];
}
if ([title isEqualToString:@"Second"]) {
if ([[arrayController arrangedObjects] count] != 0)
{
[arrayController removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[arrayController arrangedObjects ] count])]];
}
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"NS.png"],@"image", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"EM.png"],@"image", nil]] ;
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"RES.png"],@"image", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"ERS.png"],@"image", nil]] ;
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"RS.png"],@"image", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"FB.png"],@"image", nil]] ;
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"SKIN.png"],@"image", nil]];
}
[tableView reloadData];
[self windowDidLoad];
}
-(void)windowDidLoad{
[super windowDidLoad];
}
Any other suggestion??
Thanks in advance..!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论