我的代码中有一个名为“conteggio”的变量,你可以在下面看到它......这个变量必须在我的tableview的每一行增加1 ...当我尝试这样做时,我收到如下结果: 4,8,12,16等。每行的倍数为4 ......似乎它为每行重复了4次代码。为什么tableview中的代码每行重复4次?
如果我来回滚动我的表格,这些数字会变成倍数。
这里是我的代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
if (cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cellID"] autorelease];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellID"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSString *alphabet = [fevIndice objectAtIndex:[indexPath section]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
NSArray *fv = [fev filteredArrayUsingPredicate:predicate];
conteggio++;
NSString *string = [NSString stringWithFormat:@"%d", conteggio];
cell.detailTextLabel.text = string;
if ([fv count]>0) {
NSString *cellValue = [fv objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
//indexPath.section; //[fv count] numero di elementi in una section;
//cell.detailTextLabel.text = [fevMesi objectAtIndex:conteggio];
//cell.imageView.image = [UIImage imageNamed:[fevIcona objectAtIndex:]];
}
cell.detailTextLabel.numberOfLines = 3;
cell.detailTextLabel.font = [UIFont systemFontOfSize:11.0];
return cell;
}
我有部分,但我没有相同数量的行每个部分..其实这是问题...您的解决方案似乎是我的权利...我要去尝试它然后我让你知道! – Chris 2010-02-16 14:41:11
很棒!它工作正常。感谢你的回答。有了这个我已经完成了我的申请,所以我非常感谢你! – Chris 2010-02-16 15:19:50
我很高兴它的工作。请点击支票将其标记为答案。谢谢。 – DyingCactus 2010-02-16 15:38:47