UITableView的实现过程,滑动,alter弹窗删除对象
2014-08-22 09:31
766 查看
UITableView的实现过程,其中包括滑动删除,alter弹窗删除。
// // ViewController.m // tableTest // // Created by wu on 14-8-20. // Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 初始化tableView的数据 NSMutableArray *list = [NSMutableArray arrayWithObjects:@"武汉",@"上海",@"北京",@"深圳",@"广州",@"重庆",@"香港",@"台海",@"天津",@"天津",@"天津",@"天津",@"黄河",@"黄河", nil]; self.dataList = list; tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped]; // 设置tableView的数据源 tableView.dataSource = self; // 设置tableView的委托 tableView.delegate = self; // 设置tableView的背景图 tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Background.png"]]; self.myTableView = tableView; [self.view addSubview:self.myTableView]; } #pragma mark - TableView Methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.dataList count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellWithIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier]; if (cell == nil) { NSLog(@"%d",indexPath.row); cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellWithIdentifier];//创建cell,并确定cell样式为UITableViewCellStyleDefault } NSUInteger row = [indexPath row]; cell.textLabel.text = [self.dataList objectAtIndex:row]; cell.imageView.image = [UIImage imageNamed:@"2012.jpg"]; cell.detailTextLabel.text = @"详细信息"; return cell; } //点击列表对象 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *msg = [[NSString alloc] initWithFormat:@"你选择的是:%@",[self.dataList objectAtIndex:[indexPath row]]]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"删除", nil]; index = indexPath; //获取删除的位置,保存为全局变量 [alert show]; } //确定对象是否可编辑 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } //定义事件 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"%@",indexPath); if (editingStyle == UITableViewCellEditingStyleDelete) {//确定为滑动删除 //先行删除阵列中的物件 [self.dataList removeObjectAtIndex:indexPath.row]; //删除 UITableView 中的物件,并设定动画模式 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } //添加alert删除事件, - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if (buttonIndex == 1) { // 选择第二个删除按钮 [self.dataList removeObjectAtIndex:index.row]; //删除 UITableView 中的物件,并设定动画模式 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationFade]; } } @end
相关文章推荐
- ios-day13-01(私人通讯录。控制器之间的数据传递、保存密码和自动登录的实现、普通对象的归档、UITableView的局部刷新和向左滑动删除功能等等)
- UITableView小技巧--实现cell向左滑动删除,编辑等功能
- IOS UITableViewUITableView小技巧--实现cell向左滑动删除,编辑等功能
- UITableView 实现滑动删除
- iOS UITableView实现滑动删除、增加、多选
- UITableView实现Cell的滑动删除
- UITableView实现Cell的滑动删除
- UITableView小技巧--实现cell向左滑动删除,编辑等功能
- [IOS]UITableView实现Cell的滑动删除
- UITableView实现Cell的滑动删除
- UITableView实现Cell的滑动删除
- Swift学习之UITableView的实现以及滑动删除
- IOS 开发使用UITableView 实现滑动 删除等多个按钮
- ios UITableView实现单击提示,滑动删除,多选行等操作
- IOS学习之路六(UITableView滑动删除指定行)
- iOS 开发 UItableView中滑动删除 cell
- UITableView实现划动删除
- 滑动删除uitableview cell
- UITableView划动删除的实现
- UITableView实现划动删除