gpt4 book ai didi

ios - 当我在一个 View Controller 中有 2 个 TableView 时,不会为第二个 UITableView 调用 cellForRowAtIndexPath

转载 作者:行者123 更新时间:2023-11-28 22:16:01 25 4
gpt4 key购买 nike

我有一个从 xib 文件加载的 UIView。它有两个 UITableView。我想在每个 UITableView 中显示不同的数据,因此决定不使用 indexPath.section。

考虑到这一点 - 我这样写了我的 cellForRowAtIndexPath:

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *UsernameCellIdentifier = @"UsernameCell";
static NSString *PasswordCellIdentifier = @"PasswordCell";
static NSString *mailListTableViewCellIdentifier = @"Cell";
if (tableView == self.maillistTableview ){

UITableViewCell *cell = [self.maillistTableview dequeueReusableCellWithIdentifier:mailListTableViewCellIdentifier];
if (!cell){

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mailListTableViewCellIdentifier];
}


cell.textLabel.text = @"Cells";
return cell;
}


if (tableView == self.tableView){

if(indexPath.row == 0) {

self.usernameCell = (BBUsernameTableViewCell *)[tableView dequeueReusableCellWithIdentifier:UsernameCellIdentifier];

if(!self.usernameCell) {

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:UsernameCellIdentifier owner:self options:nil];

return self.usernameCell;
}

return nil;
}

当我在 cellForRowAtIndexPath 上设置断点时,它只为第一个 TableView 调用两次:self.tableView

我在 cellForRowAtIndexPath 中添加了一个 NSLog 以查看它正在查看哪个 tableView 并且它从不“检查”self.maillistTableView

我已将该 UITableView 的委托(delegate)连接到文件所有者。

有趣的是,在 numberOfRowsInSection 中,它正在为 self.maillistTableView 工作。

谁能告诉我哪里出了问题?

最佳答案

由于 numberOfRowsInSection 正在运行,请检查它的返回计数。如果数据源数组计数为零,则 cellForRowAtIndexPath 将不起作用。

关于ios - 当我在一个 View Controller 中有 2 个 TableView 时,不会为第二个 UITableView 调用 cellForRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21657081/

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