iOS疯狂详解之tableview编辑添加删除

iOS疯狂详解之SQlite数据库增删改查 // // SqLiteManager.h // MySqlite // // Created by long on 15/9/15. // Copyright (c) 2015年 WLong. All rights reserved. // #import #import "LanOuStudent.h" #import @interface SqLiteManager : NSO 阅读详情
//
//  VkoWLAccountVC.m
//  PocketUniversity
//
//  Created by long on 15-1-14.
//  Copyright (c) 2015年 WLong. All rights reserved.
//

#import "VkoWLAccountVC.h"
#import "VkoWLMoreTableViewCell.h"

#define kIcoArray @[@"消息",@"账号",@"版权"]
#define kTitleArray @[@"听筒模式",@"播放",@"清除缓存"]

@interface VkoWLAccountVC ()
{
    // 当前的编辑模式
    UITableViewCellEditingStyle _editingStyle;
    NSMutableArray *_icoArray;
    NSMutableArray *_titleArray;
}
@end

@implementation VkoWLAccountVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _icoArray = [NSMutableArray arrayWithArray:kIcoArray];
    _titleArray = [NSMutableArray arrayWithArray:kTitleArray];

    
    [self navTitle:@"账号管理" leftButtonHidden:NO];
    
    [self createView];
    
    _editingStyle = UITableViewCellEditingStyleDelete;

}

- (void)createView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.bgImageView.bottom, kUIScreenWidth, [self getMiddleViewHight]) style:(UITableViewStyleGrouped)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.allowsSelectionDuringEditing = YES;  //编辑状态下可以选中
    [self.view addSubview:_tableView];
    
    
    self.rightButton.hidden = NO;
    self.rightButton.backgroundColor = [UIColor clearColor];
    [self.rightButton setImage:[UIImage imageNamed:@"编辑"] forState:(UIControlStateNormal)];
    [self.rightButton addTarget:self action:@selector(editButtonClick:) forControlEvents:(UIControlEventTouchUpInside)];
}

- (void)editButtonClick:(UIButton *)button
{
    [self deleteData];
}


#pragma mark --- UITableView 返回Cell ---
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"VkoWLMoreTableViewCell";
    
    VkoWLMoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        
        cell = [[VkoWLMoreTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:cellIdentifier] ;
        
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.iocImageView.image = [UIImage imageNamed:_icoArray[indexPath.row]];
    cell.labelTitle.text = _titleArray[indexPath.row];
    [cell.iocImageView.layer setMasksToBounds:YES];
    [cell.iocImageView.layer setCornerRadius:25 / 2];
    cell.arrowImageView.hidden = YES;

    
    return cell;
    
}

#pragma mark ---tableView dataSource---
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titleArray.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 20+25;
}

#pragma mark --- 选中跳转 到详情界面 ---
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}


#pragma mark ---deit delete---
// 让 UITableView 和 UIViewController 变成可编辑状态
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    
    [_tableView setEditing:editing animated:animated];
}

//  指定哪一行可以编辑 哪行不能编辑
- (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

//  设置 哪一行的编辑按钮 状态 指定编辑样式
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return _editingStyle;
}

// 判断点击按钮的样式 来去做添加 或删除
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 删除的操作
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
        [_titleArray removeObjectAtIndex:indexPath.row];
        [_icoArray removeObjectAtIndex:indexPath.row];

        
        NSArray *indexPaths = @[indexPath]; // 构建 索引处的行数 的数组
        // 删除 索引的方法 后面是动画样式
        [_tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimationLeft)];
        
    }
    
    // 添加的操作
    if (editingStyle == UITableViewCellEditingStyleInsert) {
        
        NSArray *indexPaths = @[indexPath];
        [_tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimationRight)];
        
    }
    
}

#pragma mark 删除数据
- (void)deleteData
{
    _editingStyle = UITableViewCellEditingStyleDelete;
    
    BOOL isEditing = self.tableView.isEditing;
    
    [self.tableView setEditing:!isEditing animated:YES];
}

- (void)addData
{
    _editingStyle = UITableViewCellEditingStyleInsert;
    
    BOOL isEditing = self.tableView.isEditing;
    
    [self.tableView setEditing:!isEditing animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end




更多iOS疯狂详解:http://blog.csdn.net/wanglongblog

iOS开发实战:掌握TableView的删除、修改与编辑技巧 在iOS开发中,TableView是一个用于展示列表数据的核心组件。为了提高应用的用户体验,编辑功能成为了很多应用的标配,它允许用户对数据项进行修改、删除或重新排序等操作。本章节将简要介绍TableView编辑功能的基本概念和开发要点,为后续章节中对具体编辑操作(如删除、修改、滑动删除等)的深入探讨奠定基础。编辑功能不仅涉及到界面的动态变化,还涉及到数据源的管理。开发者需要确保编辑操作的每一步既直观又可靠,以防止数据丢失或错误。 阅读详情

相关推荐

ios-自定义编辑全选TableView.zip

自定义TableView编辑状态,可以全选单选,代码仅供参考没有封装。

iOS开发系列 ---- UI (TableView的编辑和多项删除操作)

增加、删除和移动效果图: 实现核心代码:#import "ViewController.h"@interface ViewController ()< UITableViewDataSource, UITableViewDelegate>@property (nonatomic, strong) NSMutableArray *arrayDS; @property (nonatomic, stro

程序员小咖的博客 3503

TableView删除,修改,编辑

TableView删除,修改,编辑,以及cell的移动

iOS-TableView编辑(多行编辑)

TableView编辑(多行编辑)Demo下载地址- 插入链接 [ 下载地址 ]OC的tableview的选中、全选、取消全选demo,(纯代码手动打造) 洲洲哥的github主页。 —— [ 洲洲哥 ] 项目结构系统界面 编辑界面 全选功能和取消全选功能可以看一下demo单选功能实现(Block)/** * cell内容 */ -(UITableViewCell *)tabl...

whuizhou的专栏 1630

iOS中tableview实现编辑、全选及删除等功能的方法示例

主要给大家介绍了关于iOS中tableview实现编辑、全选及删除等功能的相关资料,文中通过示例代码介绍的非常详细,不仅是介绍实现的方法,将实现过程中遇到的问题也都分享出来了,需要的朋友们下面来一起看看吧。

从零到一:嵌入式车载通信中间件VSOMEIP的跨平台构建之旅

本文详细介绍了嵌入式车载通信中间件VSOMEIP的跨平台构建过程,重点解析了交叉编译环境配置、Boost库编译、VSOMEIP定制化编译等关键技术环节。通过实战案例展示了在ARM架构嵌入式设备上的部署与调试方法,为开发者提供了一套完整的VSOMEIP嵌入式应用解决方案。

lilh34434的博客 202

JavaFx表格视图TableView设置单元格可编辑

JavaFx表格视图TableView设置单元格可编辑

svygh123的专栏 2049

ROS 入门教程:小乌龟仿真器和基础操作

小乌龟仿真器和ros基础操作

zlflll的博客 4137

iOS UIKit:TableView之编辑模式(3)

一般table view有编辑模式和正常模式,当table view进入编辑模式时,会在row的左边显示编辑和重排控件,如图 42所示的编辑模式时的控件布局;左边的editing control有表 61的两种图标。 表 61 table view编辑控件 图标 描述 Deletion控件 In...

a567676的博客 338

Comsol 管道导波裂纹检测:从建模到求解的完整流程解析

本文详细解析了使用Comsol Multiphysics进行管道导波裂纹检测的完整仿真流程。从几何建模、材料定义、物理场设置到网格划分与求解后处理,系统阐述了如何构建高保真虚拟模型以模拟导波与裂纹的相互作用。重点分享了激励信号设置、频散效应处理及参数化扫描等实战技巧,旨在帮助工程师与研究人员高效优化无损检测方案,降低实验成本。

weixin_29207439的博客 80

Cadence ADE实战:1GHz VCO相位噪声仿真全流程(附PSS/Pnoise避坑指南)

本文详细介绍了在Cadence ADE环境中对1GHz VCO进行相位噪声仿真的完整流程。重点剖析了PSS(周期性稳态分析)和Pnoise(周期性噪声分析)两大核心引擎的关键参数设置与避坑指南,帮助射频与模拟IC设计者准确评估VCO性能,解决仿真不收敛、结果异常等常见问题。

rock5的博客 686

iOS开发日记1-tableview编辑

今天博主有一个tableview编辑的需求,遇到了一些困难点,在此和大家分享,能够共同进步. tableview的编辑是通过[self.tableview setEditing: BOOL1 animotion: BOOL2];进入的,如果需要进入编辑模式,则调用方法,将BOOL1改为YES.如果要退出编辑模式,则调用方法,将BOOL1改为NO.BOOL2为是否使用动画. 如果你想将编辑这个b...

weixin_30535913的博客 137

1. Klipper从安装到运行

本文记录Klipper固件从安装,配置到运行的详细过程

weixin_42098934的博客 1万+

使用TableView自带的多选功能

一、简单实现1.设置tableView属性self.tableView.allowsMultipleSelectionDuringEditing = YES; 2.然后在编辑按钮显示tableView编辑状态[self.tableView setEditing:YES animated:YES]; 3.查看被选中cell的indexPath数组NSArray *indexs = self.tabl...

4421

桌面运维工程师面试题详解(一)

桌面运维工程师面试题详解(一)

jks212454的博客 1438

RAG的“诊断艺术”:从测试集结果倒追根源,精准优化检索、排序与生成

当RAG应用给出一个糟糕的答案时,开发者的第一反应可能是:“我的Prompt写得不够好?”这种基于“感觉”的猜测往往是低效的。通过构建一个包含黄金上下文信息的测试集,我们可以像一位经验丰富的医生一样,对RAG系统的各个“器官”进行独立的“健康检查”。一个用于RAG诊断的测试集,除了问题和答案,还需要包含中间环节的“黄金标准”。如果你的RAG流程包含Re-ranker,那么在评估完初期的召回后,需要单独评估Re-ranker的效果。RAG的优化是一个持续的过程,应该形成一个闭环。的文档块尽可能多地召回。

kakaZhui的博客 156

ios 编辑UITableView (添加数据 删除数据)

1 实现uitablview 代理方法 2 commitEditingStyle 实现后 可初步右滑删除 及添加删除代码 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *...

a136447572的专栏 1638

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

tableView编辑

tableView编辑 tableView编辑的步骤 1.创建按钮, 用于触发编辑 2.指定哪些可以进行编辑(dataSource方法, 可选) 3.指定编辑样式(删除或添加, delegate的方法, 可选, 默认删除) 4.编辑完成方法中, 进行删除或添加(dataSource的方法, 先删数据, 再删cell) ...

weixin_30379531的博客 208

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

ios UITableView editing 编辑状态

https://www.jianshu.com/p/f65ca53fc9ba - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 该方法支持tableview cell侧滑删除或者增加,只支持单个操作...

georgehenrywilliam的博客 2342

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

设置TableView可编辑

设置TableView可编辑  (2011-01-19 09:00:53) 转载 关键词:对tableView进行增、删操作 1.设置tableView可编辑 RootViewController.m [self.navigationItem setRightBarButtonItem:[self editButtonItem]]; -

ch_soft的专栏 1万+

关于tableview 编辑下多选择处理

1.设置可以多选择(并且设置tintColor 可以改变右侧 符号颜色)   self.tableView.allowsMultipleSelectionDuringEditing = YES;   self.tableView.tintColor = MAIN_THEME_GREEN_COLOR; 效果图: 2.定义下面修改状态的toolView   

zhanglizhi111的博客 902

iOS tableView左滑删除和编辑实现

//左滑删除 和编辑 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (NSArray&lt;UITableViewRowAction *&gt; *)tableView:(UITableView *)tableVie...

C_philadd的博客 3018

iOS ---tableView多选的一些坑

#pragma mark - 选中某行的点击操作- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    if (self.tableView.editing) {                [self.selectArr addObject:self.mode...

iotjin的专栏 2389

ios中tableview的移动添加删除

// // MJViewController.m // UITableView-编辑模式 // // Created by mj on 13-4-11. // Copyright (c) 2013年 itcast. All rights reserved. // #import "MJViewController.h" @interface MJViewCont...

weixin_34408717的博客 189

IPhone 自定义 UITableViewCell 行缩进,使cell进入编辑状态时不右移

IPhone 自定义 UITableViewCell 行缩进 在cell.m中重写setEditing: animated:以使cell进入编辑状态时不右移 转自至:http://www.gowhich.com/blog/133 网上搜索了很多,不知道是我搜索技术问题还是怎么着,就是没有找到,不过经过自己的努力,还是发现了解决的办法,因为这种情况大多数是自定的UITa

YLGWHYH的专栏 6006
上一篇: iOS疯狂详解之录制音频转换成Mp3
下一篇: iOS疯狂详解之开源库
吊炸天-狂人
博客等级 码龄12年 87粉丝 42原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址