UITableView删除行和行排序这里只介绍代理方法

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

#PRagma mark -代理方法

#pragma mark 设置cell表格高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return 60;

}

#pragma mark 当cell实行编辑功能时调用

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

if(editingStyle!=UITableViewCellEditingStyleDelete) return;

//1.删除数据源数据

[_persons removeObject:_persons[indexPath.row]];

//2.重新加载数据

[self.tableView reloadData];

}

#pragma mark 当cell实行排序功能时调用

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{

//1 拿出要移动的数据,并删除

Person *p=_persons[sourceIndexPath.row];

[_persons removeObject:p];

//2 把要移动的数据添加到目的位置

[_persons insertObject:p atIndex:destinationIndexPath.row];

}

#pragma mark 监听删除按钮

- (IBAction)remove:(UIBarButtonItem *)sender {

// self.tableView.editing=YES;//进入编辑模式

BOOL result=!self.tableView.isEditing;

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

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航