2013-07-17 106 views
3

我不知道我在做什麼錯,但cellForRowAtIndexPath表視圖的方法只被調用一次。cellForRowAtIndexPath只能被調用一次

這裏是我的代碼:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    NSLog(@"--->%d",[collaboratoresdata count]); 

    return [collaboratoresdata count]; 

} 

當我collaboratoresdata陣列被填滿,然後我打電話[_collaboratortblView reloadData]重新加載表視圖。

我成功獲得3NSLog(@"--->%d",[collaboratoresdata count]);cellForRowAtIndexPath只被調用一次。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    // add a placeholder cell while waiting on table data 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease]; 
    } 
    cell.selectionStyle=UITableViewCellSelectionStyleNone; 


    NSLog(@"tableView:%d",[indexPath row]);// i am getting 0 here than after its not calling 

    return cell; 

} 
+0

? –

+0

在你的NSLog中寫入cell.textLabel.text = @「hi」; –

+0

@HotLicks它只是顯示數組的第一個元素。 – freelancer

回答

0

檢查電池的高度,我認爲那是什麼在屏幕上顯示的問題

+0

發送邀請 – java

0
please try to set height of cell manually(custom). So, if problem of cell height then it will be resolved. below method set cell height 30 pixels. 

#pragma mark- TableView delegate Methods 
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
return 30.0f; 
}