Ios 当我在一个视图控制器中有两个表视图时,cellForRowAtIndexPath不';我不需要第二个UITableView
我有一个从xib文件加载的UIView。它有两个UITableView。我希望在每个UITableView中显示不同的数据,并决定不使用indexPath.section 考虑到这一点,我写下了我的Ios 当我在一个视图控制器中有两个表视图时,cellForRowAtIndexPath不';我不需要第二个UITableView,ios,iphone,objective-c,uitableview,Ios,Iphone,Objective C,Uitableview,我有一个从xib文件加载的UIView。它有两个UITableView。我希望在每个UITableView中显示不同的数据,并决定不使用indexPath.section 考虑到这一点,我写下了我的cellforrowatinexpath如下: -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *Us
cellforrowatinexpath
如下:
-(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;
}
当我在cellforrowatinexpath
上设置断点时,第一个表视图只调用两次:self.tableView
我在cellForRowAtIndexPath中添加了一个NSLog,以查看它查看的是哪个表视图,并且它从不“检查”self.maillistTableView
我已将UITableView的代理连接到文件所有者
有趣的是,在numberOfRowsInSection
中,它正在为self.maillistTableView
工作
有人能告诉我哪里出了问题吗?可能是
self.maillistTableView
不调用重载数据由于行数部分
正在工作,请检查它的返回计数。如果数据源数组计数为零,则cellforrowatinexpath
将不工作。是“self.maillistTableView
”还是“self.maillistTableView
”?案件敏感性问题。您的源代码片段说明了一件事,而您的“它正在为…”说明了另一件事。elf.maillistTableView的numberOfRowsInSection返回了什么。很抱歉,这只是self.maillistTableView中的一个副本和过去的错误。两者在代码中拼写相同。数组的计数将正确返回到表中view@Akhilrajtr-看来你有什么发现。我的数组计数实际上是零。我没有正确地检查它,这就是为什么它没有调用cellforrowatinexpath的原因——因为没有要显示的单元格。把这颗彗星作为答案,我会接受的。谢谢加载视图后调用[self.maillistavbleview reloadData]似乎有效。很奇怪,它在第一次加载视图时并没有这样做?正如在其他评论中所添加的,这是我的问题。非常感谢。