UITableViewDelegate cellForRowAtIndexPath not called

江枫思渺然 提交于 2019-12-13 04:48:47

问题


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:

  1. numberOfRowsInSection returns 0
  2. numberOfSectionsInTableView return 0
  3. dataSource not properly set
  4. heightForRowAtIndexPath returns 0
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!