macos - NSTableView 与 plist 文件

标签 macos cocoa xcode4 nstableview nswindowcontroller

我对 Mac 应用程序开发非常陌生。所以只是做一些实际练习。

我想创建一个表格 View 来显示我的 plist 文件中的数据。
我有一个窗口 Controller 类和窗口 Controller .xib 文件。
我将 NSTableView 拖放到 .xib 文件中。
并使用此代码加载 plist 文件

- (void)windowDidLoad
{
    [super windowDidLoad];

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *path = [bundle pathForResource:@"tenth" ofType:@"plist"];
    file = [[NSArray alloc] initWithContentsOfFile:path];

}

现在我应该怎么做才能在我的 TableView 中显示行?
我必须使用哪种方法?如何??

就像我们在 IOS 开发中使用的那样

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

NSArray *temp = [file objectAtIndex:indexPath.row];
cell.textLabel.text = [temp objectAtIndex:0];
return cell;
}

最佳答案

您可以使用 bindings使用 NSArrayControllerimplement the NSTableViewDataSource protocol .

推荐阅读:Table View Programming Guide .

关于macos - NSTableView 与 plist 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7385792/

相关文章:

objective-c - 给定进程 ID,确定进程是否是 Mac 上的窗口进程

java - 将参数发送到我的捆绑 java 应用程序

cocoa 选择器问题

cocoa - 如何让 NSTableView 的唯一列占据 TableView 的所有宽度?

macos - 如何使 NSTableView 透明?

objective-c - 在 Cocoa View 层次结构中,什么决定了 subview 的位置?

macos - 如何在 Mac OSX 上降级 JRE/JDK?

swift - 如何让NSTextView的高度一直高于实际高度20px?

objective-c - NSCollectionView 中的选择突出显示

syntax-highlighting - 如何在Xcode 4中为文件类型分配语法颜色?