简体   繁体   中英

Selector gets called in numberOfRowsInSection but not in cellForRowAtIndexPath

I have this code to fill a UITableView and the one returning the numberOfRowsInSection works fine. The selector using appDelegate in the cellForRowAtIndexPath part is not called. Whats wrong here?

   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
 VIP_GeburtstagAppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
 [appDelegate getEntriesForDate:section];

 return appDelegate.namesForDay.count;

}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    VIP_GeburtstagAppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

 [appDelegate getEntriesForDate:indexPath.section];

Methods are called. Selectors are (more or less) names of methods; they are not called.

If -tableView:numberOfRowsInSection: returns 0, there are no cells, so it doesn't call -tableView:cellForRowAtIndexPath: .

Perhaps that part of the table isn't showing yet, and the UITableView is loading lazily. If so, scroll up so that those cells are visible and your delegate should be called.

tableView:numberOfRowsInSection: Does return 366 or similar so tableView:cellForRowAtIndexPath: gets called. When I exchange the cell.textLabel.text to @"John Doe" it works just fine.

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