0

Maybe it's a similar beginning, but it's true.

first of all sorry if this isn't formatted correctly, first time doing this. I've been using stackoverflow to find help for a long time now and it's been very helpful (thank you all), but this is the first time I've posted a question of my own. This question has been asked many times, but when I call [self.tableView reloadTable] the methods numberOfSectionsInTableView and numberOfRowsInSection are called but not cellForRowAtIndexPath.

Every answer I've seen when searching has been a variation of:

  1. The tableView is nil
  2. numberOfRowsInSection is 0
  3. tableView's delegate/data source not set. None of these are the case for me so I'm wondering what else could be wrong.

But I'm not sure 4. calling reloadTable on the wrong uiTableView. Or it's about some other false.

Now my APP is similar to dropbox, first when we log into it, we get a file list(include directories) in the TableView.also, I added a toolbar in the bottom of the view by [self.navigationController.view addSubview:toolBar], when I touch the button item "refresh", it calls [self.tableView reloadData] and works well.

Second when we select a directory we will get a new file list table which is pushViewController by self.navigationController, but this time when we touch the "refresh", the statement [self.tableView reloadData] calls numberOfSections, numberOfRows, not cellForRowAtIndexPath

Any ideas as to why cellForRow's not being called the Second time? Thanks in advance.

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];
}

My return number of section and row in table view is not 0.

When I added NSLog(@"Calling reloadData on %@", self.tableView); into "refresh":

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

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

Then it returns Calling reloadData on ; contentOffset: {0, 0}>. Delegate: FileListViewController, DataSource: FileListViewController

Philip
  • 3
  • 5

1 Answers1

1

You should not manually call [self viewDidLoad]. This method is designed to be overridden, and is automatically called. For more information, please read this documentation.

legege
  • 421
  • 4
  • 12
  • Thanks for your advice. I've deleted [self viewDidLoad], I agree with you. But now the problem persist, [self.tableView reloadData] does not call cellForRowAtIndexPath when I touch the "refresh" button under a directory. Is it because I alloc a new tableView FileListViewController *fileListViewController = [[FileListViewController alloc] init] ? – Philip Jul 05 '12 at 06:49
  • Probably you didn't wire new tableView properly(datasource and delegate) or manually alloc/init new tableView and assign it to property that later/earlier was init from xib. – Timur Kuchkarov Feb 19 '13 at 04:10