NSTAbleView不显示NSMutableArray的内容 [英] NSTAbleView is not displaying contents of the NSMutableArray
问题描述
在Xcode 4中,我创建了一个名为 Tabletest
的新可可应用程序,在xib上添加了 NSTableView
并将其控制拖动到应用程序的 delegate对象
(在创建新的Cocoa应用程序时自动创建).我设置表的dataSource并将其委托给名为 Tabletest App Delegate
的应用程序的委托对象.
In Xcode 4 I created a new Cocoa application called Tabletest
, on the xib I added a NSTableView
and control-dragged it to the app's delegate object
(created automatically when you create the new Cocoa app). I set the table's dataSource and delegate to the app's delegate object called Tabletest App Delegate
.
在 tabletestAppDelegate.h
和 tabletestAppDelegate.m
上,我添加了(显然)必需的
On tabletestAppDelegate.h
and tabletestAppDelegate.m
I added the (apparently) required
- (int)numberOfRowsInTableView:(NSTableView *)tableView;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row;
- (int)numberOfRowsInTableView:(NSTableView *)tableView
{
return (int)[myArray count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
return [myArray objectAtIndex:row];
}
并声明了 NSMutableArray
,例如 NSMutableArray * myArray;
然后,我将表控件拖放到 .h
上,并创建了一个像这样的属性:
and declared an NSMutableArray
like NSMutableArray * myArray;
Then I control-dragged the table to the .h
and created a property like:
@property (assign) IBOutlet NSTableView *myTable;
在 .m
文件上,我添加了 numberOfRowsInTableView
和(id)tableView ...
On the .m
file I added the implementation of numberOfRowsInTableView
and (id)tableView...
并添加:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
myArray = [[NSMutableArray alloc] initWithCapacity:10];
int i = 0;
for(i=0; i<10;i++)
{
[myArray insertObject: [NSString stringWithFormat:@"This is string %d!",i+1] atIndex:i];
}
NSEnumerator * enumerator = [myArray objectEnumerator];
id element;
while((element = [enumerator nextObject]))
{
// Do your thing with the object.
NSLog(@"%@", element);
}
}
`NSLog显示数组已满,但信息从不显示在表上.我想念什么?我是可可的新手,我不知道为什么将信息添加到简单表是如此复杂.
The `NSLog show the array gets filled but the info never shows on the table. What am I missing? I am a complete newbie on Cocoa and I have no idea why adding information to a simple table is so complicated.
感谢您的帮助.
推荐答案
我将回答我自己的问题,添加
I'll answer my own question, add
[_myTable reloadData];
这篇关于NSTAbleView不显示NSMutableArray的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!