简体   繁体   中英

cellForRowAtIndexPath not being called?

I am working on a project where I need to populate the cells in a table and have them show on the screen. I've got the table to show but now data is being shown in the cells. I've tried using breakpoints and found that this method never gets called. The method just before it (numberOfRowsInSection) does get called. Any suggestions?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        Resident *aResident = (Resident *)[appDelegate.residents objectAtIndex:indexPath.row];   
        cell.textLabel.text = aResident.name;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        return cell;
    }

您是否为TableView设置了委托和数据源?

是的,numberOfRowsInSection可能返回0。显示它以及您填充数据源的位置。

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