UITableView 实例详解 滑动编辑 headerView
2013-01-15 15:38
363 查看
self.dataArray = [[[NSMutableArray alloc]init] autorelease]; NSArray *array = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"Beijing",@"$500", nil],[NSArray arrayWithObjects:@"ShangHai",@"$510", nil],[NSArray arrayWithObjects:@"Guangzhou",@"$540", nil],[NSArray arrayWithObjects:@"Wuhan",@"$513", nil], nil]; [dataArray addObjectsFromArray:array]; int height = [UIScreen mainScreen].applicationFrame.size.height; self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, height - 40) style:UITableViewStylePlain]; self.tableView.dataSource = self; self.tableView.delegate = self; [self.view addSubview:self.tableView];
点击 home button,进入编辑
纵向滑动tableCell 出现编辑按钮
#pragma mark - UITableViewDataSource/Delegate //返回table 行数 - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataArray.count; } - (UITableViewCell*) tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"cell"; UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]; } NSArray *data = [dataArray objectAtIndex:indexPath.row]; cell.textLabel.text = [data objectAtIndex:0]; cell.detailTextLabel.text = [data objectAtIndex:1]; cell.detailTextLabel.textColor = [UIColor redColor]; return cell; } //- (NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { // NSString *headerString = @"Address Price"; // return headerString; //} - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { return @"删除"; } //纵向滑动时响应,出现编辑按钮 - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"Start editing!"); } -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { //纵向滑动时出现编辑按钮 return YES; } //让行可以移动 -(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)tableView:(UITableView *)_tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { //编辑完响应事件 UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath]; NSLog(@"title:%@",cell.textLabel.text); NSLog(@"price:%@",cell.detailTextLabel.text); [dataArray removeObjectAtIndex:indexPath.row]; [tableView reloadData]; } //设置table headerView - (UIView*) tableView:(UITableView *)_tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, _tableView.frame.size.width, 20)] autorelease]; UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 20)]; leftLabel.textColor = [UIColor orangeColor]; UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(_tableView.frame.size.width - 100, 0, 90, 20)]; rightLabel.textColor = [UIColor orangeColor]; leftLabel.text = @"Address"; rightLabel.text = @"Price"; rightLabel.textAlignment = NSTextAlignmentRight; leftLabel.backgroundColor = [UIColor clearColor]; rightLabel.backgroundColor = [UIColor clearColor]; UIImageView *backImage = [[UIImageView alloc]initWithFrame:headerView.frame]; backImage.image = [UIImage imageNamed:@"back.png"]; [headerView addSubview:backImage]; [headerView addSubview:leftLabel]; [headerView addSubview:rightLabel]; [leftLabel release]; [rightLabel release]; [backImage release]; return headerView; }
相关文章推荐
- UITableView 实例详解 滑动编辑 headerView
- android界面开发:ViewPager的详解,并用于仿微博滑动实例和图片滚动实例
- IOS UITableViewUITableView小技巧--实现cell向左滑动删除,编辑等功能
- IOS 照片编辑的view封装的实例详解
- UITableView小技巧--实现cell向左滑动删除,编辑等功能
- IOS控件学习之UITableView代码实例详解
- Android Fragment滑动组件ViewPager的实例详解
- UITableView编辑模式详解
- IOS UITableView颜色设置的实例详解
- UITableView小技巧--实现cell向左滑动删除,编辑等功能
- IOS第七天(6:UiTableView编辑模式, 拖动位置 ,滑动删除)
- UITableView实例详解
- UITableView滑动,编辑内容消失
- 三、IOS UITableView详解
- ViewPager 详解(五)-----使用Fragment实现ViewPager滑动
- 实例讲解iOS应用开发中使用UITableView创建自定义表格
- UITableView详解
- UITableView SDK嘱托方法详解
- UITableView滑动性能优化扩展
- UITableView 滑动cell显示不全