未调用 UITableViewDelegate cellForRowAtIndexPath [英] UITableViewDelegate cellForRowAtIndexPath not called

查看:28
本文介绍了未调用 UITableViewDelegate cellForRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图控制器,我在情节提要中设置了一个表视图,并从 mapViewController 向它推送转场.当用户触摸 ios 提供的注解标注时,函数 calloutAccessoryControllTapped 被调用,并通过名为

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];

这很好用.

但是,我用在 XIB 中布局的自定义标注替换了 ios 提供的标注.它有一个按钮,其操作会导致执行上面的同一行代码,并且会发生 tableView 的 Segue,但是 tableViewController 的 cellForRowAtIndexPath 永远不会被调用.然而,titleForHeaderInSection 确实被调用,这表明它充当 UITableViewDataSource.

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.

有人有什么想法吗?

每个代码请求:

.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

推荐答案

cellForRowAtIndexPath 可能由于以下一个(或多个)原因而无法调用:

cellForRowAtIndexPath may not be called because one(or more) of the following reasons:

  1. numberOfRowsInSection 返回 0
  2. numberOfSectionsInTableView 返回 0
  3. 数据源设置不正确
  4. heightForRowAtIndexPath 返回 0
  5. 表格的高度和/或宽度的框架大小为 0

在你的情况下,我最好的选择是 1(在方法中放置一个断点以查看当表要求行数时返回多少行).我最糟糕的经历是调试 5 号 :)

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 :)

这篇关于未调用 UITableViewDelegate cellForRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆