我正在制作一个列出 Documents 字典中文件的 iOS。我想在 UITableView 中显示这些数据,问题是它不起作用。它将数据加载到视图中。然后应用程序冻结并调用EXC_BAD_ACCESS
这是我的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
timesRun = 0;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectoryPath error:nil];
[bundleRoot release];
NSLog(@"Count: %i",[dirContents count]);
return [dirContents count];
}
- (UITableViewCell *)tableView:(UITableView *)tableViewData cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
int Locatation = indexPath.row;
Locatation++;
cell = [tableViewData dequeueReusableCellWithIdentifier:@"MyCells"];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"]autorelease];
}
//cell.textLabel.text = [NSString stringWithFormat:@"Cell: %i",Locatation];
cell.textLabel.text = [dirContents objectAtIndex:timesRun];
timesRun++;
return cell;
NSLog(@"Did return");
}
- (void)tableView:(UITableView *)tableViewDat didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%@",cell.textLabel.text);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}