相关疑难解决方法(0)

在UITableView中使用插入行

我希望我的UITableView的行为类似于联系人编辑器中的表格,即用户应该点击编辑,并且每个部分的底部应该出现一个"添加新类别"行.

我使用下面的代码来执行此操作,但问题是没有平滑过渡,因为在联系人中.相反,新行突然出现.我怎样才能获得动画?

另外,我如何回应"添加新类别"行的点击?在我当前的实现中,该行不可单击.

用户开始编辑时是否需要重新加载数据?我这样做是因为否则不会绘制插入行.

谢谢.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self.tableView setEditing:editing animated:animated];
    [tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)_tableView numberOfRowsInSection:(NSInteger)section {
    // ...
    if( self.tableView.editing ) 
        return 1 + rowCount;
}

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // .....
    NSArray* items = ...;
    if( indexPath.row >= [items count] ) {
        cell.textLabel.text = @"add new category";
    }
    // ...

    return cell;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray* items = ...;

    if( indexPath.row == [items count] ) …
Run Code Online (Sandbox Code Playgroud)

iphone editing insert objective-c uitableview

32
推荐指数
2
解决办法
5万
查看次数

标签 统计

editing ×1

insert ×1

iphone ×1

objective-c ×1

uitableview ×1