我对 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使用 NSArrayController
或 implement the NSTableViewDataSource
protocol .
推荐阅读:Table View Programming Guide .
关于macos - NSTableView 与 plist 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7385792/