UITableView 实例详解 滑动编辑 headerView
来源:互联网 发布:云计算通俗讲义第二版 编辑:程序博客网 时间:2024/06/05 10:12
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
- ios UITableView 滑动 headerView footerView 跟随问题
- UITableView滑动,编辑内容消失
- UITableView编辑模式详解
- UITableview 去除滑动删除 编辑状态删除
- UITableView实例详解
- UItableview section headerview黏性
- 去掉UItableview headerview黏性
- 去掉UItableview headerview黏性
- 去掉UItableview headerview黏性
- 掉UItableview headerview黏性
- 去掉UItableview headerview黏性
- 去掉UItableview headerview黏性
- 去掉UItableview headerview黏性
- iOS - UITableView HeaderView
- 去掉UItableview headerview黏性(sticky)
- 去掉UItableview headerview黏性(sticky)
- 去掉UItableview headerview黏性(sticky)
- HDU 1211 RSA 解密
- oracle10g分区表的自动维护(原创)
- java.lang.IllegalArgumentException: pointerIndex out of range
- FreeBSD 下载 安装
- Jquery -- 快捷键
- UITableView 实例详解 滑动编辑 headerView
- 互斥量Mutex
- Mongodb 安装篇(Linux版+windows版)
- 3种自动登录MySQL命令行模式的方法
- SDWebImage 内部运行机制浅析
- set proxy for svn on linux server
- 企业架构设计为企业IT建设量体裁衣
- CPU 管态和目态
- error LNK2001: 无法解析的外部符号 _sqlite3_api问题的解决