【发布时间】:2014-04-19 03:47:49
【问题描述】:
- 我是
Objective-C的新手,非常感谢任何帮助。 - 我有一个
TableView,它成功地从我的 Xcode 项目中的Data.plist文件中拉回列表,但我需要它从 文档目录 中拉取。 - 我看过很多关于此的帖子,但似乎无法让它为我工作。
- 下面是我的 .m 文件。就像我说的,它会拉回数据,但我需要根据我的 Documents plist 副本动态更改它。
提前致谢!
@synthesize content = _content;
- (NSArray *)content
{
if (!_content) {
_content = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]];
}
return _content;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.content count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = [[self.content objectAtIndex:indexPath.row] valueForKey:@"Name"];
cell.detailTextLabel.text = [[self.content objectAtIndex:indexPath.row] valueForKey:@"Score"];
return cell;
}
【问题讨论】:
-
此代码从资源包中读取。从 Documents 文件夹中读取数据的代码在哪里?您是否有将初始文件放入 Documents 文件夹的代码?
标签: ios objective-c uitableview plist