2015-02-11 42 views
0

所以我發現了很多問題和在這個問題上的答案,但我似乎仍然不能解決我的問題。 我有這樣的:在一個視圖控制器中的兩個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

回答

0

檢查- (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

1

我有完全相同的問題,因爲你。 我發現最簡潔的解決方案是製作2個數據源類。這樣你的視圖控制器中的代碼就少了很多。 基本上是這樣的

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

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

這大大降低了的數據源協議方法內if語句量。這樣,您可以像在一個表視圖中一樣,在每個數據源類中實現數據源方法。

希望這會有所幫助。

相關問題