Oc AlertView 添加/删除/修改 到表格 -demo
来源:互联网 发布:魔卡幻想 淘宝 编辑:程序博客网 时间:2024/06/08 15:15
注意:AlertView 要使用8.0版本
先添加导航条
控制器1
#import "ViewController.h"@interface ViewController ()<UIActionSheetDelegate,UIAlertViewDelegate,UITableViewDataSource,UITableViewDelegate>@property(nonatomic ,strong)UITableView *table;@property(nonatomic ,strong)NSMutableArray *Marr;@property(nonatomic ,assign)NSInteger integer;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title=@"表格"; UITableView * table =[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain]; table.delegate=self; table.dataSource=self; [self.view addSubview:table]; self.Marr=[NSMutableArray arrayWithObjects:@"n",@"n",@"n",@"n",@"n", nil]; UIBarButtonItem * left =[[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStylePlain target:self action:@selector(Edit)]; self.navigationItem.leftBarButtonItem=left; UIBarButtonItem * right =[[UIBarButtonItem alloc]initWithTitle:@"添加" style:UIBarButtonItemStylePlain target:self action:@selector(Add)]; self.navigationItem.rightBarButtonItem=right; self.table = table;}//编辑方法- (void)Edit { //开始编辑 [self.table setEditing:!self.table.editing animated:YES];}- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ //从数据源上删除 [self.Marr removeObjectAtIndex:0]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop]; [self.table setEditing:NO animated:YES];}//添加和修改-(void)Add{ UIAlertView * alert =[[UIAlertView alloc]initWithTitle:@"信息" message:@"添加" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; alert.alertViewStyle=UIAlertViewStylePlainTextInput; alert.delegate=self; alert.tag=100; [alert show];}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ UITextField * text =[alertView textFieldAtIndex:0]; if (buttonIndex==1&&alertView.tag==100) { [self.Marr addObject:text.text]; } else if(buttonIndex==1 && alertView.tag==101){ [self.Marr replaceObjectAtIndex:self.integer withObject:text.text]; } [self.table reloadData];}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.Marr.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString * cellID =@"cell"; UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellID]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } cell.textLabel.text=self.Marr[indexPath.row]; return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ self.integer=indexPath.row; UIActionSheet * action =[[UIActionSheet alloc]initWithTitle:@"修改信息" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"修改", nil]; action.delegate=self; [action showInView:self.view];}- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex==0) { UIAlertView * alert1 =[[UIAlertView alloc]initWithTitle:@"信息" message:@"修改信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; alert1.alertViewStyle=UIAlertViewStylePlainTextInput; alert1.delegate=self; alert1.tag=101; [alert1 show]; }}@end
阅读全文
0 0
- Oc AlertView 添加/删除/修改 到表格 -demo
- 动态添加修改删除html表格内容
- 表格点选和添加、删除、修改
- angularJs 表格添加删除修改查询
- Java从入门到精通 - Swing表格JTable利用tableModel添加行修改行删除行
- java从入门到精髓 - Swing表格JTable利用tableModel添加行修改行删除行
- Js操作表格-对表格单元格的添加删除修改
- Dom操作 表格的添加行,删除行,修改行,
- Tableviewer中为表格添加删除、修改link
- 对表格的动态的添加和删除修改
- jquery表单验证添加到表格再删除easyNew
- jQuery实现用户添加删除,符合条件追加到表格
- Swift实现自定义AlertView,灵活添加自定义视图到AlertView,可响应事件
- 表格动态添加删除
- 动态添加删除表格
- 添加删除表格
- 制作表格,添加,删除
- angularJs表格添加删除
- 夸克浏览器产品分析报告
- 使用eclipse构建springboot项目的解决的一些问题
- 第八周项目四__稀疏矩阵的三元组表示的实现及应用(1)
- Android 基于TCP协议的网络通信
- 自学自动化测试Python2.7.14+selenium 2.53.6 +pycharm
- Oc AlertView 添加/删除/修改 到表格 -demo
- ES6-正则的扩展-sticky属性和flags属性
- Oc Snow Animation(下雪动画)~demo
- 解决 Cannot open D:\Program Files\Anaconda3\Scripts\pip-script.py 问题
- 线段树学习笔记及模板
- 【机房收费】这一路走来的弯路
- WebCrawler-HttpClient
- servlet简介及ServletContext对象
- 螺旋矩阵