ITeye博客

表UITableViewController 的一些操作方法

helmsman_xcode · 2011-08-15 16:47 · ios-综合基础文章 · 移动开发 · Markdown

是否可以对表进行编辑

[self.tableView setEditing:BOOL animated:YES];

 

BOOL 为YES 可对表中的数据进行如下操作:

移动

 

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    NSUInteger fromRow = [sourceIndexPath row];
    NSUInteger toRow = [destinationIndexPath row];
    
    id object = [[listOne objectAtIndex:fromRow] retain];
    
    [listOne removeObjectAtIndex:fromRow];
    [listOne insertObject:object atIndex:toRow];
    
}

 

删除

 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    [self.listOne removeObjectAtIndex:row];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

 

对表进行添加操作以后就表进行更新

 

 [self.tableView reloadData];

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。