0

也许这是一个相似的开始,但这是真的。

首先很抱歉,如果格式不正确,第一次这样做。很长一段时间以来,我一直在使用 stackoverflow 来寻求帮助,它非常有帮助(谢谢大家),但这是我第一次发布自己的问题。这个问题已经被问过很多次了,但是当我调用 [self.tableView reloadTable] 时,方法 numberOfSectionsInTableView 和 numberOfRowsInSection 被调用但不是 cellForRowAtIndexPath。

我在搜索时看到的每个答案都是以下内容的变体:

  1. 表视图是nil
  2. numberOfRowsInSection是 0
  3. 未设置 tableView 的委托/数据源。这些都不是我的情况,所以我想知道还有什么问题。

但我不确定 4. 在错误的 uiTableView 上调用 reloadTable。或者它是关于其他一些错误的。

现在我的APP类似于dropbox,首先当我们登录它时,我们在TableView中得到一个文件列表(包括目录)。另外,我在视图底部添加了一个工具栏[self.navigationController.view addSubview:toolBar],当我触摸按钮项目“刷新",它调用[self.tableView reloadData]并且运行良好。

其次,当我们选择一个目录时,我们会得到一个新的文件列表表,它是pushViewControllerby self.navigationController,但是这次当我们触摸“刷新”时,语句 [self.tableView reloadData] 调用 numberOfSections,numberOfRows,而不是 cellForRowAtIndexPath

关于为什么第二次不调用 cellForRow 的任何想法?提前致谢。

FileListViewController.h
@interface FileListViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>    

FileListViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (isDir) {       
        FileListViewController *fileListViewController = [[FileListViewController alloc] init];
        [self.navigationController pushViewController:fileListViewController animated:YES];
    }
}

- (void)refresh
{
    [Utilities refresh];//Utilities is my custom class.

    [self viewDidLoad];
    [self.tableView reloadData];
}

我在表格视图中返回的部分和行数不是 0。

当我添加NSLog(@"Calling reloadData on %@", self.tableView);到“刷新”中时:

- (void)refresh
{
    [Utilities refresh];//Utilities is my custom class.

    [self viewDidLoad];
    NSLog(@"Calling reloadData on %@", self.tableView);
    [self.tableView reloadData];
}

然后它返回 Calling reloadData on ; 内容偏移:{0, 0}>。委托:FileListViewController,数据源:FileListViewController

4

1 回答 1

1

您不应该手动调用[self viewDidLoad]. 此方法旨在被覆盖,并自动调用。有关更多信息,请阅读此文档

于 2012-06-30T02:29:33.677 回答