问题
I have a table view controller with a tableview that I set up in the storyboard with a push segue to it from the mapViewController. When the user touched the ios provided annotation callout the function calloutAccessoryControllTapped is called, and it indirectly by way of a notification called
 [self performSegueWithIdentifier:@"SequeToConversationList" sender:self];
This works fine.
However, I replaced the ios supplied callout with a custom callout layed out in a XIB. It has a button with an action that results in the same line of code above being executed, and the Segue to the tableView happens, however cellForRowAtIndexPath of the tableViewController never gets called. titleForHeaderInSection does however get called which indicates that it is acting as the UITableViewDataSource.
Anyone have any ideas?
Per code request:
.h:
#import <UIKit/UIKit.h>
@interface PhListTableViewController : UITableViewController <UITableViewDataSource,UITableViewDelegate>
@end
.m:
#import "PhListTableViewController.h"
#import "PhSettings.h"
@interface PhListTableViewController ()
@end
@implementation PhListTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    PhSettings *settings=[PhSettings getInstance];
    settings.currentViewController = CONV_LIST;
    //...
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    PhSettings *settings=[PhSettings getInstance];
    return [settings.myUUIDsList count];
}
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @"Active:";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    // Configure the cell...
    PhSettings *settings=[PhSettings getInstance];
    NSMutableString *s = [NSMutableString string];
    [s appendString:@"Alias:"];
    [s appendString:[[settings.myUUIDsList objectAtIndex:indexPath.row] userAlias]];
    [s appendString:@"Category: "];
    [s appendString:[[settings.myUUIDsList objectAtIndex:indexPath.row] category]];
    cell.textLabel.text=s;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  //indexPath.row
  // ...
}
@end
回答1:
cellForRowAtIndexPath may not be called because one(or more) of the following reasons:
- numberOfRowsInSection returns 0
 - numberOfSectionsInTableView return 0
 - dataSource not properly set
 - heightForRowAtIndexPath returns 0
 - table has frame size of 0 for height and/or width
 
In your case my best shot is number 1(place a breakpoint in the method to see how many rows you are returning when table ask for rows count). My worst experience was with debugging number 5 :)
来源:https://stackoverflow.com/questions/27674170/uitableviewdelegate-cellforrowatindexpath-not-called