首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要设置reuseIdentifier,但不可能

需要设置reuseIdentifier,但不可能
EN

Stack Overflow用户
提问于 2014-01-17 22:48:34
回答 1查看 190关注 0票数 0

我的应用程序有点像MAC OS下的FinderFileManager。我可以显示文件系统的根目录。但是通过目录的Navigation会产生问题。

didSelectRowAtIndexPath方法中,我创建了当前TableViewController的一个新实例。我将DelegateDataSource设置为self。现在我遇到的问题是:新创建的实例的TableViewCells没有resueIdentifier。该值为NULL。我不能设置它,因为它是只读的。那么,如何让新的单元具有特定的reuseIdentifier呢?

下面是我的didSelectRowAtIndexPath方法中的代码

代码语言:javascript
复制
-(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];
}

      }

如果你需要更多的代码来帮助我,请让我知道。

谢谢,克里斯

EN

回答 1

Stack Overflow用户

发布于 2014-03-29 17:29:06

也许我对这个问题的回答太迟了。但这是我的想法。

代码语言:javascript
复制
UITableViewCell *newCell = [newDir.tableView cellForRowAtIndexPath:indexPath];
 NSLog(@"reuseIdentifier NewCell: %@",newCell.reuseIdentifier);  // <- is NULL

因为没有创建tableView,所以为NULL。推送完成后,会立即创建。如果你想把一些参数传递给你的表,你应该在FileTableViewController.h中实现这些变量,然后在你的didSelectRowAtIndexPath中使用如下代码:

代码语言:javascript
复制
FileTableViewController *newDir = [[FileTableViewController alloc] init];
newDir.SomeData = cell.textLabel.text;

更重要的一点是,如果FileTableViewController是UITableViewController,则不应该设置dataSourcedelegate,尤其是在当前的viewController中。因为这样做,所以您将delegate设置为当前viewController的自身(而不是创建的FileTableVC )。否则,如果FileTableVC不是UITAbleViewController类,则应该在FileTableVC的viewDidLoad中创建委托和数据源。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21188687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档