自定义UITableViewCell上的delete按钮
来源:互联网 发布:mac系统丢失 编辑:程序博客网 时间:2024/05/14 15:23
1.通过UITableViewDelegate方法可以实现删除 tableview中某一行
//滑动删除
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
[bookInforemoveObjectAtIndex:row];//bookInfo为当前table中显示的array
[tableView deleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationLeft];
}
此时删除按钮为Delete,如果想显示为“删除” 中文的话,则需要实现UITableViewDelegate中的- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath方
- - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
- return @"删除";
- }
2.这只是让默认的Delete按钮显示成了中文的删除按钮而已,如果想将这个删除按钮换成其他图片形式的,怎么办呢?
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *RootViewControllerCell = @"RootViewControllerCell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RootViewControllerCell];
- if(cell == nil)
- {
- cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell]autorelease];
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal];
- [button setFrame:CGRectMake(280, 10, 30, 30)];
- [button addTarget:self action:@selector(del:) forControlEvents:UIControlEventTouchUpInside];
- [cell.contentView addSubview:button];
- }
- cell.textLabel.text = [array objectAtIndex:[indexPath row]];
- cell.tag = [indexPath row];
- NSArray *subviews = [cell.contentView subviews];
- for(id view in subviews)
- {
- if([view isKindOfClass:[UIButton class]])
- {
- [view setTag:[indexPath row]];
- [cell.contentView bringSubviewToFront:view];
- }
- }
- return cell;
- }
- -(void)del:(UIButton *)button
- {
- NSArray *visiblecells = [self.table visibleCells];
- for(UITableViewCell *cell in visiblecells)
- {
- if(cell.tag == button.tag)
- {
- [array removeObjectAtIndex:[cell tag]];
- [table reloadData];
- break;
- }
- }
- }
效果如下:
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的删除按钮
- 自定义UITableViewCell 上的多个按钮点击事件处理
- 自定义UITableViewCell 上的多个按钮点击事件处理
- 自定义UITableViewCell 上的多个按钮点击事件处理
- 自定义UITableViewCell 上的多个按钮点击事件处理
- 自定义UITableViewCell 上的多个按钮点击事件处理
- 自定义UITableViewCell 上的多个按钮点击事件处理
- 自定义UITableViewCell上的按钮点击事件处理
- 自定义UITableViewCell 上的多个按钮点击事件处理
- 自定义UITableViewCell 上按钮点击事件处理
- UITableViewCell上的删除按钮(tableView自带的和自定义的)
- UITableViewCell上的按钮点击事件处理
- rake 版本冲突解决
- Android中PopupWindow的用法
- Phone时代已经来临
- 软件架构师的特点
- vim - command summary
- 自定义UITableViewCell上的delete按钮
- 设置当前页面中的一个IFrame的自适应高度
- 中国更需张瑞敏还是任正非
- 四、U-boot的使用(三)
- 中国彩电企业或错过OLED班车
- Android-需求(十二):第三方apk修改
- linux安装gcc和gcc-c++
- hbase和hive整合
- X Phone大预测:Google到底想干什么