iOS 开发 UItableView中滑动删除 cell
2012-11-19 12:06
471 查看
主要是就是两个函数
一:- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
相应editingStyle事件处理
在这里主要相应UITableViewCellEditingStyleDelete:
二:(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
在这个函数中设置那个cell设置成 什么样的editingStyle删除,插入,无
UITableViewCellEditingStyleDelete
UITableViewCellEditingStyleInsert
UITableViewCellEditingStyleNone
需要注意的问题:在删除对应cell中的内容时,也要删除这个cell,否则运行时显示效果就像没有刷新 一样,多出一个cell。而使用[tableView reloadData];[self loadView];刷新都不管用。必须使用deleteRowsAtIndexPaths:withRowAnimation:函数删除这个cell
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView reloadData];据说reloadData只是从新加载表项内容,而不会重新设置表内cection中cell的个数。
#pragma mark Table view methods
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"accessoryTypeForRowWithIndexPath");
if( 0 == indexPath.section ){
if( indexPath.row == [m_URLArray count]){
return UITableViewCellAccessoryDetailDisclosureButton;
}
GFdataURL *currentURl ;
currentURl = [[[GFdataURL alloc] init] autorelease];
currentURl = [m_URLArray objectAtIndex: indexPath.row];
//[currentURl release];
//int i = [indexPath row];
if([currentURl.m_strSubscribe isEqualToString:@"y"]){
return UITableViewCellAccessoryCheckmark;
}else{
return UITableViewCellAccessoryNone;
}
}else{
return UITableViewCellAccessoryDetailDisclosureButton;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"accessoryButtonTappedForRowWithIndexPath");
//NSInteger sectionSelect = [indexPath section];
//NSInteger rowSelect = [indexPath row];
//NSLog(@"选中了%d--%d",sectionSelect,rowSelect);
switch(indexPath.section){
case 0:
//资讯设置
if( indexPath.row == [m_URLArray count]){
m_addNewsURL = [[addNewsURL alloc] initWithNibName:@"addNewsURL" bundle:nil];
[self.navigationController pushViewController:m_addNewsURL animated:YES];
}
break;
case 1:
//货币设置
switch(indexPath.row){
case 0:
//跳转到默认类型 设置页面
m_defaltType = [[currencySettingForDefaultTypeViewController alloc] initWithNibName:@"currencySettingForDefaultType" bundle:nil];
m_defaltType.isDefaultType = YES;
[self.navigationController pushViewController:m_defaltType animated:YES];
break;
case 1:
//跳转到兑换类型 设置页面
m_defaltType = [[currencySettingForDefaultTypeViewController alloc] initWithNibName:@"currencySettingForDefaultType" bundle:nil];
m_defaltType.isDefaultType = NO;
[self.navigationController pushViewController:m_defaltType animated:YES];
break;
default :
;
}
break;
default :
;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
//for section 0 中的滑动删除效果
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
if( (0 == indexPath.section) && (indexPath.row != [m_URLArray count]) ){
return UITableViewCellEditingStyleDelete;
}else{
return UITableViewCellEditingStyleNone;
}
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"commitEditingStyle");
if (editingStyle == UITableViewCellEditingStyleDelete) {
GFdataURL *currentURl ;
currentURl = [[GFdataURL alloc] init];
//currentURl = [m_URLArray objectAtIndex: indexPath.row];
currentURl = [[m_URLArray objectAtIndex:indexPath.row] retain];
GFDBC *mydatabase;
mydatabase =[[GFDBC alloc] init];
[mydatabase deleteURL:currentURl.m_strURL];
[currentURl release];
currentURl = nil;
if(m_URLArray !=nil){
[m_URLArray release];
m_URLArray =[[NSMutableArray alloc] init];
}
m_URLArray = [[mydatabase getAllURL] retain];
//
[mydatabase release];
//[m_tableView deleteRowsAtIndexPaths:indexPath.row withRowAnimation:UITableViewRowAnimationFade];
//[tableView reloadData];
//[self loadView];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
一:- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
相应editingStyle事件处理
在这里主要相应UITableViewCellEditingStyleDelete:
二:(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
在这个函数中设置那个cell设置成 什么样的editingStyle删除,插入,无
UITableViewCellEditingStyleDelete
UITableViewCellEditingStyleInsert
UITableViewCellEditingStyleNone
需要注意的问题:在删除对应cell中的内容时,也要删除这个cell,否则运行时显示效果就像没有刷新 一样,多出一个cell。而使用[tableView reloadData];[self loadView];刷新都不管用。必须使用deleteRowsAtIndexPaths:withRowAnimation:函数删除这个cell
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView reloadData];据说reloadData只是从新加载表项内容,而不会重新设置表内cection中cell的个数。
#pragma mark Table view methods
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"accessoryTypeForRowWithIndexPath");
if( 0 == indexPath.section ){
if( indexPath.row == [m_URLArray count]){
return UITableViewCellAccessoryDetailDisclosureButton;
}
GFdataURL *currentURl ;
currentURl = [[[GFdataURL alloc] init] autorelease];
currentURl = [m_URLArray objectAtIndex: indexPath.row];
//[currentURl release];
//int i = [indexPath row];
if([currentURl.m_strSubscribe isEqualToString:@"y"]){
return UITableViewCellAccessoryCheckmark;
}else{
return UITableViewCellAccessoryNone;
}
}else{
return UITableViewCellAccessoryDetailDisclosureButton;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"accessoryButtonTappedForRowWithIndexPath");
//NSInteger sectionSelect = [indexPath section];
//NSInteger rowSelect = [indexPath row];
//NSLog(@"选中了%d--%d",sectionSelect,rowSelect);
switch(indexPath.section){
case 0:
//资讯设置
if( indexPath.row == [m_URLArray count]){
m_addNewsURL = [[addNewsURL alloc] initWithNibName:@"addNewsURL" bundle:nil];
[self.navigationController pushViewController:m_addNewsURL animated:YES];
}
break;
case 1:
//货币设置
switch(indexPath.row){
case 0:
//跳转到默认类型 设置页面
m_defaltType = [[currencySettingForDefaultTypeViewController alloc] initWithNibName:@"currencySettingForDefaultType" bundle:nil];
m_defaltType.isDefaultType = YES;
[self.navigationController pushViewController:m_defaltType animated:YES];
break;
case 1:
//跳转到兑换类型 设置页面
m_defaltType = [[currencySettingForDefaultTypeViewController alloc] initWithNibName:@"currencySettingForDefaultType" bundle:nil];
m_defaltType.isDefaultType = NO;
[self.navigationController pushViewController:m_defaltType animated:YES];
break;
default :
;
}
break;
default :
;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
//for section 0 中的滑动删除效果
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
if( (0 == indexPath.section) && (indexPath.row != [m_URLArray count]) ){
return UITableViewCellEditingStyleDelete;
}else{
return UITableViewCellEditingStyleNone;
}
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"commitEditingStyle");
if (editingStyle == UITableViewCellEditingStyleDelete) {
GFdataURL *currentURl ;
currentURl = [[GFdataURL alloc] init];
//currentURl = [m_URLArray objectAtIndex: indexPath.row];
currentURl = [[m_URLArray objectAtIndex:indexPath.row] retain];
GFDBC *mydatabase;
mydatabase =[[GFDBC alloc] init];
[mydatabase deleteURL:currentURl.m_strURL];
[currentURl release];
currentURl = nil;
if(m_URLArray !=nil){
[m_URLArray release];
m_URLArray =[[NSMutableArray alloc] init];
}
m_URLArray = [[mydatabase getAllURL] retain];
//
[mydatabase release];
//[m_tableView deleteRowsAtIndexPaths:indexPath.row withRowAnimation:UITableViewRowAnimationFade];
//[tableView reloadData];
//[self loadView];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
相关文章推荐
- (iOS)UITableView只允许部分cell支持滑动删除
- [IOS]UITableView实现Cell的滑动删除
- iOS开发学习之利用系统远程UITableView 自定义滑动删除按钮、增加自定义滑动按钮方法
- iOS开发中实现UITableView的Cell左划删除等自定义功能
- IOS 开发使用UITableView 实现滑动 删除等多个按钮
- IOS UITableViewUITableView小技巧--实现cell向左滑动删除,编辑等功能
- iOS UITableView 支持滑动删除 Cell
- iOS开发:UITableView编辑——cell的删除和移动
- iOS开发-UI控件:让UITableView自动滑动(定位)到某一行cell
- IOS开发(25)之删除UITableView的Cell
- iOS开发:UITableView实现侧滑删除cell的功能
- iOS项目开发小技巧 (三) --UITableView实现Cell左划删除等自定义功能
- iOS开发—去除UITableView多余Cell的横线
- ios UITableView 区和cell一起滑动
- iOS开发:UITableView的优化技巧-异步绘制Cell
- ios开发-设置UITableView/Cell背景设置
- iOS中uitableview滑动删除添加按钮
- iOS开发 UITableView之cell
- iOS开发之UITableView左滑删除等自定义功能
- IOS开发相关07--UITableView默认选中第一个cell