简体   繁体   中英

UITableView -> numberOfRowsInSection:(NSInteger)section returns wrong value

My 2nd time today... But here are so many good developers...

Hi,

I have some troubles with my tableView... If the view will appear my table reloads its data, but it doesn't update the numbersOfRowsInSection...

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"COUNTER: %i",[content count]);
    return [content count];
}

The log says the first time I load the page the right value. But if I add an object and reload the data, this function isn't calling.

Is there anyone who know the solution?

Thanks, mavrick3.

EDIT:

Heres how I call [table reloadData]

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if ([content count] != 0) {
        self.content = [[[[NSArray alloc] initWithContentsOfFile:[FileManager filePath]] objectAtIndex:row_] objectForKey:@"faecher"];
        [table reloadData];
        NSLog(@"----%@",content);
    }
}

And yes, the dataSource and delegate are connected and they are both implemented in my header.

If you call reloadData on a UITableview object and you're it's dataSource then this method should be called called.

Are you sure that you have assigned your table view to your property (ie dragged it across in interface builder?)

I suspect that you have only made your controller the dataSource of your table view (hence the first time it loads it gets the value). After that your calls to reloadData won't work because the property in your view controller is still nil.


You can test this by putting an NSLog just before you call reloadData - if it outputs nil then you've not connected it.

NSLog(@"%@", myTable);
[myTable reloadData];

any compiler warnings? Is "table" actually an instance of UITableView?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM