2015-10-27 23 views
1

坦率地说,我知道如何插入新的自定义行结束没有reloadData,但现在我想知道的是如何插入新的自定义行UITable end end而reloadData。在reloadData插入新的自定义行同时reloadData Xcode

这是我的一段代码插入新的自定义行,而reloadData。但是新插入的行出现在表格的顶部,这不是我想要的。

CoachPadItem *newCoachPadItem = [[CoachPadItem alloc]init]; 
    newCoachPadItem.coachpadDescription = textView.text; 
    newCoachPadItem.coachpadTagId = @"0"; 
    [_tagPointsArray addObject:newCoachPadItem]; 
    [_coachpadTableView reloadData]; 

的cellForRowAtIndexPath

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

    // Configure the cell... 
    CoachPadPointCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CoachPadPointCell" forIndexPath:indexPath]; 

    if (cell == nil) { 
     cell = [[CoachPadPointCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CoachPadPointCell"]; 
    } 

    counter += 1; 

    cell.tagBtn.hidden = YES; 
    cell.btnRemove.hidden = YES; 

    cell.tagBtn.userInteractionEnabled = canEdit; 
    [cell.tagBtn addTarget:self action:@selector(removeTag:) forControlEvents:UIControlEventTouchUpInside]; 
    [cell.btnRemove addTarget:self action:@selector(removePad:) forControlEvents:UIControlEventTouchUpInside]; 
    cell.btnRemove.tag = counter; 
    cell.txtPoint.delegate = self; 
    cell.txtPoint.tag = counter; 
    cell.txtPoint.textContainer.maximumNumberOfLines = 2; 
    cell.tagBtn.tag = counter; 
    cell.txtPoint.textAlignment = NSTextAlignmentLeft; 
    cell.txtPoint.backgroundColor = [UIColor clearColor]; 
    cell.txtPoint.userInteractionEnabled = canEdit; 

    cell.backgroundColor = [UIColor clearColor]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    CoachPadItem *curr = _tagPointsArray[indexPath.row]; 
    cell.txtPoint.text = cure.MyDesc; 

    return cell; 
} 

请帮助我如何把新的一行UITable结束?你在你的cellForRowAtIndexPath方法使用_tagPointsArray

+0

,你能否告诉装载电池'cellforrowatindexpath'的方法呢? – anhtu

+0

@anhtu我已经修改我的问题,因为添加cellforrowatindexpath。谢谢。 – ppshein

+0

应将新行插入底部。太奇怪了。 – anhtu

回答

2

我不确定发生了什么事。

但是,如果[_tagPointsArray addObject:newCoachPadItem];原因新插入的行出现在表的顶部这是不是我想要的,你可以尝试:

[_tagPointsArray insertObject: newCoachPadItem atIndex:0]; 
+0

插入的行本身正确显示在UITableView的末尾。 – ppshein

1

信任,iOS设备会自动照顾新行插入,我可以看到你以前reloadData呼叫你的表视图更新了模型_tagPointsArray

只需向下滚动即可看到!

编辑:后OP编辑后

检查这两行:

CoachPadItem *curr = _tagPointsArray[indexPath.row]; 
cell.txtPoint.text = cure.MyDesc; 

您还没有消耗来自阵列所获取的模型对象。如果对象被添加到数组中的正确位置,这必须工作。 仔细检查你的模型数据的位置,以及我提到的上述两行。

+1

但他在问题中说:“新插入的行出现在桌子顶部,这不是我想要的。” – anhtu