打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
objective

滑动列表行(UITableViewCell)出现删除按钮时,默认是英文“delete”,这份代码片段能够将“delete”变成中文”删除“,甚至可以自定义删除按钮的形状。

//通过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 @"删除";    }    //或者,最简单的方式,将plist中的Localization native development region改为China即可//这只是让默认的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;            }        }    }//该片段来自于http://outofmemory.cn
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
UITableview 单选和重用
ios UITableView中Cell重用机制导致内容重复解决方法
iOS 多选删除(附tableViewTips及单选删除)
UITableView长按Cell出现选择(剪切复制粘贴全选)菜单并执行相应的操作
tableview中cell的设置
可任意自定义的UITableViewCell
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服