美文网首页
增删改查

增删改查

作者: iOS_阿辉 | 来源:发表于2017-12-15 09:43 被阅读0次

,,,

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate>
@property (nonatomic,strong) NSMutableArray *array;
@property (nonatomic,strong) UITableView *tableViews;
@property (nonatomic,strong) UIAlertView *alert;
@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.tableViews];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(edit)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
    }

  • (void)edit{
    if (self.tableViews.isEditing == NO) {
    self.tableViews.editing = YES;
    }else if (self.tableViews.isEditing == YES){
    self.tableViews.editing = NO;
    }
    }

  • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
    UITextField *tf = [self.alert textFieldAtIndex:0];
    [self.array addObject:tf.text];
    [self.tableViews reloadData];
    }
    }

  • (void)add{
    self.alert = [[UIAlertView alloc]initWithTitle:@"提示框" message:@"输入您的姓名" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
    self.alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    [self.alert show];
    }

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.array.count;
    }

  • (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.array removeObject:self.array[indexPath.row]];
    [self.tableViews reloadData];
    }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *tableIdentfier = @"table";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentfier];
    if (!cell) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentfier];
    }
    cell.textLabel.text = self.array[indexPath.row];
    return cell;
    }

  • (NSMutableArray *)array{
    if (!_array) {
    _array = [[NSMutableArray alloc]initWithObjects:@"张三",@"李四",@"王五", nil];
    }
    return _array;
    }

  • (UITableView *)tableViews{
    if (!_tableViews) {
    _tableViews = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [_tableViews setDelegate:self];
    [_tableViews setDataSource:self];
    }
    return _tableViews;
    }
    ,,,

相关文章

  • mysql的插入语句

    MySQL增删改查之增insert、replace

  • MYSQL数据库的增删改查

    MYSQL数据库的增删改查 一.对于库的增删改查 增create database 库名称;create data...

  • 关于python的list的增查删改

    说到增查删改,想起了数据库,我们在关系型数据库当中就会对表进行增查删改。 在python当中我们也可以对list进...

  • 0812 A

    mongodb 增删改查 增: db.createCollection("name", {options:numb...

  • 增删改

    对于表中的操作,就是增删改查,查内容较多,这里先说增删改。 1.增(insert或者load) 即插入数据,多行插...

  • SQL查询结构总结

    SQL 增删改查 对数据库有修改的操作是:增删改 增 insert into 表名 values(); 删 del...

  • 2018-03-03

    rails c增删改查 增:user = User.create(name:'Jack', age:'18') 删...

  • 函数和增删改查(运用)

    增删改查 (基本命令) 1 . 增 inset(position,value)append(value)exten...

  • 表内容的操作

    对表数据进行增删改查(curd) 增(insert into): auto_increment自增长 SELECT...

  • 数据库表的增删改查

    crud 对表的增删改查 增insert into1.完全插入:例如:insert into 表名 values(...

网友评论

      本文标题:增删改查

      本文链接:https://www.haomeiwen.com/subject/lrerwxtx.html