【问题标题】:NSTableView with plist file带有 plist 文件的 NSTableView
【发布时间】:2011-09-12 09:29:29
【问题描述】:

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

我想创建一个表格视图来显示我的 plist 文件中的数据。
我有一个 windowcontroller 类和 window 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];

}

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

就像我们在 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;
}

【问题讨论】:

  • 我认为您不会想用 NSTableView 来表示属性列表。在 OS X 上,树通常用 NSOutlineView 表示。属性列表文件不是扁平结构,将它们扁平化会导致问题...

标签: macos cocoa xcode4 nstableview nswindowcontroller


【解决方案1】:

您可以将bindingsNSArrayControllerimplement the NSTableViewDataSource protocol 一起使用。

推荐阅读:Table View Programming Guide

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多