简体   繁体   中英

[tableView numberOfRowsInSection:0 always returns 0

The data populates, but [tableView numberOfRowsInSection:0] always returns 0. There is only one section in my table. What types of things can cause this behavior?

If there is only one section always in your table, go with the following coed...

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 1;
    }

Or in case your number of sections are depending on datasource, you can return the count of your datasource.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];

Try this. It might help you.

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