未调用UITableViewDelegate cellForRowAtIndexPath

时间:2014-12-28 06:23:06

标签: ios uitableview segue

我有一个带有tableview的表视图控制器,我在故事板中设置了mapview,并从mapViewController中推送到它。当用户触摸ios提供的注释标注时,调用函数calloutAccessoryControllTapped,并通过名为

的通知间接调用它。
 [self performSegueWithIdentifier:@"SequeToConversationList" sender:self];

这很好用。

但是,我将ios提供的callout替换为XIB中的自定义标注。它有一个按钮,其动作导致上面的代码行被执行,并且发生了对tableView的Segue,但是tableViewController的cellForRowAtIndexPath永远不会被调用。但是,titleForHeaderInSection会被调用,表示它充当UITableViewDataSource。

有人有什么想法吗?

每个代码请求:

·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 个答案:

答案 0 :(得分:4)

可能因为一个(或多个)原因而无法调用cellForRowAtIndexPath:

  1. numberOfRowsInSection返回0
  2. numberOfSectionsInTableView返回0
  3. dataSource未正确设置
  4. heightForRowAtIndexPath返回0
  5. 表的框架大小为0,高度和/或宽度
  6. 在你的情况下,我的最佳镜头是数字1(在方法中放置一个断点,以查看当表要求行计数时返回的行数)。我最糟糕的经历是调试5号:)

相关问题