效果图

#import <UIKit/UIKit.h>#import "RootTableViewController.h"@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end

#import "AppDelegate.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window.rootViewController=[[UINavigationController alloc]initWithRootViewController:[[RootTableViewController alloc]initWithStyle:UITableViewStylePlain]];return YES;
}

#import <UIKit/UIKit.h>@interface RootTableViewController : UITableViewController@property(strong,nonatomic)  NSMutableArray * array;@end

#import "RootTableViewController.h"
#import "ViewController.h"
@interface RootTableViewController ()<postValuedelegate>
{//记录选中行的索引值NSIndexPath * currentInfrxPath;
}
@end@implementation RootTableViewController- (void)viewDidLoad {[super viewDidLoad];//添加liftbarabuttonself.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addItem)];self.navigationItem.rightBarButtonItem = self.editButtonItem;self.array=[NSMutableArray array];[self.array addObject:@"zhangsan"];[self.array addObject:@"lisi"];[self.array addObject:@"wangwu"];[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuseIdentifier"];// Uncomment the following line to preserve selection between presentations.// self.clearsSelectionOnViewWillAppear = NO;// Uncomment the following line to display an Edit button in the navigation bar for this view controller.}-(void)addItem
{UIAlertController *alertcontroller=[UIAlertController alertControllerWithTitle:@"确定要增加吗" message:@"输入姓名?" preferredStyle:(UIAlertControllerStyleAlert)];UIAlertAction * ok=[UIAlertAction actionWithTitle:@"增加" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {UITextField * textName= alertcontroller.textFields[0];[self.array addObject:textName.text];[self.tableView reloadData];//        NSLog(@"真正的操作");}];[alertcontroller addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {textField.placeholder=@"添加姓名";}];[alertcontroller addAction:ok];[self presentViewController:alertcontroller animated:YES completion:nil];}-(void)postvalue:(NSString *)username
{//为集合指定索引位置元素赋值self.array[currentInfrxPath.row]=username;NSLog(@"%@",username);//刷新数据[self.tableView reloadData];
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}#pragma mark - Table view data source- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 1;
}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return self.array.count;
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier" forIndexPath:indexPath];cell.textLabel.text=self.array[indexPath.row];return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{currentInfrxPath=indexPath;ViewController *vc=[[ViewController alloc]init];vc.name=self.array[indexPath.row];vc.delegate=self;[self.navigationController pushViewController:vc animated:YES];
}// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {// Return NO if you do not want the specified item to be editable.return YES;
}// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {if (editingStyle == UITableViewCellEditingStyleDelete) {// Delete the row from the data source[self.array removeObjectAtIndex:currentInfrxPath.row];[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];} else if (editingStyle == UITableViewCellEditingStyleInsert) {// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view}
}// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {//1.找到指定位置集合元素NSString * name= self.array[fromIndexPath.row];//2.删除集合元素[self.array removeObject:name];//3插入集合[self.array  insertObject:name atIndex:toIndexPath.row];NSLog(@"%@",self.array);}// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {// Return NO if you do not want the item to be re-orderable.return YES;
}/*
#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

#import <UIKit/UIKit.h>@protocol postValuedelegate <NSObject>-(void)postvalue:(NSString *) username;@end@interface ViewController : UIViewController<UITextFieldDelegate>@property(strong,nonatomic) NSString *name;@property(strong,nonatomic) UITextField * textNmae;@property(strong,nonatomic) id<postValuedelegate> delegate;@end

#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor=[UIColor greenColor];self.textNmae=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 150, 44)];self.textNmae.delegate=self;self.textNmae.borderStyle=1;self.textNmae.text=self.name;[self.view addSubview:self.textNmae];
}-(BOOL)textFieldShouldReturn:(UITextField *)textField
{if (self.delegate) {[self.delegate postvalue:textField.text];}if ([textField isFirstResponder]) {[textField resignFirstResponder];}[self.navigationController popViewControllerAnimated:YES];return YES;
}
- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}@end

转载于:https://www.cnblogs.com/fume/p/5293015.html

对简单单元格的增删改相关推荐

  1. FineUI大版本升级,外置ExtJS库、去AXD化、表格合计行、表格可编辑单元格的增删改、顶部菜单框架

    FineUI v3.3.0 更新的内容非常多,所以一下子从 v3.2.6 连跳 3 个小版本,直接来到了 v3.3.0.详细的更新记录请参考这里:http://fineui.com/version 主 ...

  2. FineUI大版本升级,外置ExtJS库、去AXD化、表格合计行、表格可编辑单元格的增删改、顶部菜单框架...

    FineUI v3.3.0 更新的内容非常多,所以一下子从 v3.2.6 连跳 3 个小版本,直接来到了 v3.3.0.详细的更新记录请参考这里:http://fineui.com/version 主 ...

  3. FineUI大版本升级,外置ExtJS库、去AXD化、表格合计行、表格可编辑单元格的增删改、顶......

    2019独角兽企业重金招聘Python工程师标准>>> FineUI v3.3.0 更新的内容非常多,所以一下子从 v3.2.6 连跳 3 个小版本,直接来到了 v3.3.0.详细的 ...

  4. ASP.NET操作简单的xml,增删改查

    温习一下对xml的简单操作,贴出来收藏 xml文件格式: <?xml version="1.0" encoding="utf-8"?> <st ...

  5. springboot整合mybatis实现简单的单表增删改查(完整代码可下载)

    搭建项目 项目简单效果,前端效果丑的一批,主要是后端功能实现: springboot增删改查 csdn完整代码下载链接: springboot+mybatis Gitee下载地址: Gitee下载地址 ...

  6. JDBC中用控制台简单对数据库进行增删改查操作(IDEA.2023)

    文章目录 前言 一.首先是每个操作共用的操作大纲 1.注册驱动 2.创建连接 3.编写SQL语句结果,动态值的部分使用?代替 4.创建prepareStatement,并且传入SQL语句的结果 5.占 ...

  7. MVC的简单项目 客户信息-增删改查 崔希凡JavaWeb 之 day-19

    目录 增删改查 以"增"举例 查询 改 查询与修改总结 删除 高级搜索 增删改查 以"增"举例 Servlet的功能:(MVC中的C,控制层,一般包名servl ...

  8. 使用SpringBoot一小时快速搭建一个简单后台管理(增删改查)(超详细教程)

    最近也是临近期末了,各种的期末大作业,后台管理也是很多地方需要用到的,为了方便大家能快速上手,快速搭建一个简单的后台管理,我花了两天时间整理了一下 我会从0开始介绍,从数据库的设计到前端页面的引入最后 ...

  9. python增删改查的框架_简单的Django框架增删改查操作

    Django之orm对MysqL数据库的增删改查操作简介: 利用Django中orm来查找数据库中的数据,对数据库进行增.删.改.查: 增:新增数据 # 操作数据库user表新增记录 # 方式1: u ...

最新文章

  1. java bufferedimage颜色_使用BufferedImage进行渐变色操作
  2. 特斯拉FSD车端感知解析
  3. 第九课.朴素贝叶斯分类器
  4. Druid(准)实时分析统计数据库——列存储+高效压缩
  5. OracleJDBC
  6. 合格前端系列第五弹- Virtual Dom Diff
  7. 【網址收藏】解决VSCODE“因为在此系统上禁止运行脚本“报错
  8. 有些文档,本来想整理整理贴出来,
  9. 计算机硬件设施落后,论中等职业学校计算机教学现状及解决方案
  10. C-Free 5.0注册码
  11. sql面试题:问题1:查询每个同学的学生编号、学生姓名、选课总数...问题2:查询“张三”老师所授课程的学生中,成绩最高的学生信息...
  12. 第39级台阶python实现
  13. abandon connection, owner thread: DubboServerHandler错误原因
  14. 2020-2021读书记录
  15. winform chart 网格线设置
  16. Java 春招、秋招面试总结
  17. 国内的知名产品及其开发语言v0.0.1
  18. java 时间轮_基于时间轮的定时任务
  19. Compose实战-以MVI的方式写Compose
  20. 前端面试日记(7)网易有道

热门文章

  1. Java XML解析工具 JDOM介绍及使用实例
  2. 大唐电信JAVA笔试题面试题
  3. 第三章 学习ICE 3.0--Slice语言
  4. Leetcode 204. 计数质数 解题思路及C++实现
  5. python没有上方工具栏_Python体验(08)-图形界面之工具栏和状态栏
  6. Request —— 获取请求行数据 获取请求头数据 获取请求体数据
  7. 帆软finereport实现动态切换分组和列表模式
  8. jquery lt选择器与gt选择器
  9. WeUI用Toast组件显示Loading
  10. STM32 RTC BKP备份数据区数据丢失问题的讨论