gpt4 book ai didi

ios - 未调用 UITableViewDelegate cellForRowAtIndexPath

转载 作者:行者123 更新时间:2023-11-28 18:59:29 25 4
gpt4 key购买 nike

我有一个带有 TableView 的 TableView Controller ,我在 Storyboard 中设置了一个 TableView Controller ,并从 mapViewController 向它推送 segue。当用户触摸 ios 提供的注释标注时,将调用函数 calloutAccessoryControllTapped,它会间接通过称为

的通知的方式进行调用
 [self performSegueWithIdentifier:@"SequeToConversationList" sender:self];

这很好用。

但是,我用 XIB 中布局的自定义标注替换了 ios 提供的标注。它有一个带有操作的按钮,该操作会导致执行上面的同一行代码,并且会发生到 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
// ...
}

@结束

最佳答案

cellForRowAtIndexPath 可能不会被调用,因为以下一个(或多个)原因:

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

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

关于ios - 未调用 UITableViewDelegate cellForRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27674170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com