`
helmsman_xcode
  • 浏览: 25359 次
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

表UITableViewController 的一些操作方法

 
阅读更多

是否可以对表进行编辑


[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];
 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics