在一个视图控制器中的两个UITableView的

问题描述:

所以我发现了很多问题和在这个问题上的答案,但我似乎仍然不能解决我的问题。 我有这样的:在一个视图控制器中的两个UITableView的

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    if(tableView == self.moduleTableView){ 
     UITableViewCell *cell = [_moduleTableView dequeueReusableCellWithIdentifier:@"TableIDCell"]; 
     if (cell == nil) { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableIDCell"]; 
     } 

这就是所有罚款和工程为moduleTableView,我有代码来填充单个细胞。 但是,我后来有一个if(tableView == theOtherTableview)和代码永远不会执行,(已使用断点检查)。因此,第二个tableview不会加载和填充。 我已经为同做,如果在numberOfRows方法,说明我宣布:

self.tblEvents.delegate = self; 
    self.tblEvents.dataSource = self; 
    self.otherTblEvents.delegate = self; 
    self.otherTblEvents.dataSource = self; 

,它仍然无法正常工作,我失去了什么?我想我已经正确链接落实到故事板,我只是不能让它重新加载cellForRowAtIndexPath:方法而(tableView == OtherTableView)

感谢

+0

检查其他TableView的委托设置.... – Damo 2015-02-11 14:51:54

检查- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section方法返回零值(空数组数),细胞只有在numberOfRowsInSection方法返回非零值时才会调用行方法。

numberOfRowsInSection应该返回一个非零值

+0

只是为了阐明'tableView:numberOfRowsInSection:'不应该返回一个数组,只是一个数字。通常这将是某些数组的'count'属性。 – 2015-02-11 14:47:43

+0

为什么世界上有像我这么多的白痴和像你这样的好人不多。谢谢,这解决了我的问题! – simbo64 2015-02-11 15:01:26

+0

我的荣幸@ simbo64 – Saif 2015-02-11 15:02:19

我有完全相同的问题,因为你。 我发现最简洁的解决方案是制作2个数据源类。这样你的视图控制器中的代码就少了很多。 基本上是这样的

DatasourceTblEvents *ds1 = [DatasourceTblEvents new]; 
    DatasourceotherTblEvents *ds2 = [DatasourceotherTblEvents new]; 

    self.tblEvents.dataSource = ds1; 
    self.otherTblEvents.dataSource = ds2; 

这大大降低了的数据源协议方法内if语句量。这样,您可以像在一个表视图中一样,在每个数据源类中实现数据源方法。

希望这会有所帮助。