![](/img/trans.png)
[英]What are the reasons for cellForRowAtIndexPath getting called more than once for every row
[英]cellForRowAtIndexPath is getting called only once
我不知道我做錯了什么,但表視圖的cellForRowAtIndexPath
方法只被調用一次。
這是我的代碼:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"--->%d",[collaboratoresdata count]);
return [collaboratoresdata count];
}
當我的collaboratoresdata
數組被填滿時,我正在調用[_collaboratortblView reloadData]
來重新加載表視圖。
我在NSLog(@"--->%d",[collaboratoresdata count]);
成功獲得3
分NSLog(@"--->%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;
}
檢查細胞的高度,我認為這是問題
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.