我的应用程序有点像MAC OS下的Finder的FileManager。我可以显示文件系统的根目录。但是通过目录的Navigation会产生问题。
在didSelectRowAtIndexPath方法中,我创建了当前TableViewController的一个新实例。我将Delegate和DataSource设置为self。现在我遇到的问题是:新创建的实例的TableViewCells没有resueIdentifier。该值为NULL。我不能设置它,因为它是只读的。那么,如何让新的单元具有特定的reuseIdentifier呢?
下面是我的didSelectRowAtIndexPath方法中的代码
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if(cell.accessoryType == UITableViewCellAccessoryDisclosureIndicator)
{
NSLog(@"Entered Directory");
NSLog(@"reuseIdentifier: %@",cell.reuseIdentifier); // <- value: "fileCell"
FileTableViewController *newDir = [[FileTableViewController alloc] init];
newDir.tableView.dataSource = self;
newDir.tableView.delegate = self;
[newDir setDirectory:cell.textLabel.text];
UITableViewCell *newCell = [newDir.tableView cellForRowAtIndexPath:indexPath];
NSLog(@"reuseIdentifier NewCell: %@",newCell.reuseIdentifier); // <- is NULL
//[newDir setTitle: [fileManager currentDirectoryPath]];
/*[self setDirectory:cell.textLabel.text];
self.title = [NSString stringWithFormat:@"%@", [fileManager currentDirectoryPath]];
[self.tableView reloadData];
*/
[self.navigationController pushViewController:newDir animated:YES];
}
}如果你需要更多的代码来帮助我,请让我知道。
谢谢,克里斯
发布于 2014-03-29 17:29:06
也许我对这个问题的回答太迟了。但这是我的想法。
UITableViewCell *newCell = [newDir.tableView cellForRowAtIndexPath:indexPath];
NSLog(@"reuseIdentifier NewCell: %@",newCell.reuseIdentifier); // <- is NULL因为没有创建tableView,所以为NULL。推送完成后,会立即创建。如果你想把一些参数传递给你的表,你应该在FileTableViewController.h中实现这些变量,然后在你的didSelectRowAtIndexPath中使用如下代码:
FileTableViewController *newDir = [[FileTableViewController alloc] init];
newDir.SomeData = cell.textLabel.text;更重要的一点是,如果FileTableViewController是UITableViewController,则不应该设置dataSource和delegate,尤其是在当前的viewController中。因为这样做,所以您将delegate设置为当前viewController的自身(而不是创建的FileTableVC )。否则,如果FileTableVC不是UITAbleViewController类,则应该在FileTableVC的viewDidLoad中创建委托和数据源。
https://stackoverflow.com/questions/21188687
复制相似问题