NSTableView与plist文件 [英] NSTableView with plist file

查看:95
本文介绍了NSTableView与plist文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是mac应用程序开发的新手。所以只是做一些实际的练习。

I am very new to mac app development. so just doing some practical exercise.

我想创建一个tableview显示我的plist文件中的数据。

我有一个windowcontroller类和窗口controller.xib文件。

将NSTableView拖放到.xib文件。

并使用此代码加载plist文件

I want to create a tableview which display data from my plist file.
I have one windowcontroller class and window controller.xib file.
I drag and drop NSTableView to the .xib file.
and using this code to load plist file

- (void)windowDidLoad
{
    [super windowDidLoad];

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

}

现在在我的tableview中显示行应该怎么办? ?

我必须使用哪种方法?如何??

Now what should i do for displaying rows in my tableview??
Which method i have to use? and how??

在IOS开发中,我们使用

like in IOS development we are using

- (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;
}


推荐答案

href =http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html =nofollow>绑定与 NSArrayController 实现 NSTableViewDataSource 协议

You can use either bindings with an NSArrayController or implement the NSTableViewDataSource protocol.

推荐阅读:表视图编程指南

这篇关于NSTableView与plist文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆