iOS 不同按钮点击显示不同的tableview数据

点击按钮弹出列表选择  项目中常遇到,我用的是系统中的tableview 原理就是先创建好列表的UI,将其隐藏,在点击事件中操作的时候在显现出来  同时刷新列表 这里用tag标记值来识别你刷新的是哪一个数据源哪一个按钮执行的操作,好了 原理就是这样的  那么下面就开始代码分析吧

还有一个更炫的在这里呢

1、首先创建两个数组来包含列表中的数据源

@interface BLEViewController ()

{

    NSArray *array,*array2;

    int flag;

}

@property (weak,nonatomic)IBOutlet UIButton *Scan;

@property (weak,nonatomic)IBOutletUIButton *Print;


@end


@implementation BLEViewController


- (void)viewDidLoad {

    [superviewDidLoad];

2、因为我用的是xib创建的所以先将其隐藏

    _tableV.hidden =YES;


    array = @[@"时间地方",@"氨基酸的",@"AIDS",@"爱学",

                       @"比屋而封",@"啊防护等级撒",@"阿斯顿",@"卡戴珊覅",

                       @"你骄傲的",@"不雅",@"额外调查",@"卡丁车"];

    

    array2 =@[@"阿萨德地方",@"束带结发的",@"iun",@"爱那就",

              @"比屋觉得女警爱封",@"而无办法级撒",@"我放假饿",@"i32fj",

              @"2哦哦诶积分",@"饿哦妇女",@"爱发呆呢查",@"i"];

3、数据开始判断 标识

- (IBAction)openDoor:(UIButton *)sender {

    flag =1;

    _tableV.hidden =NO;

    [_tableVreloadData];

    

    

    [UIViewanimateWithDuration:0.3fanimations:^{

        self.tableV.frame =CGRectMake(0, -self.view.frame.size.height,self.view.frame.size.width,self.view.frame.size.height);

        

    } completion:^(BOOL finished) {


        self.tableV.frame =CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);


        

    }];


    

    

    

}

- (IBAction)OOO:(UIButton *)sender {

    flag =2;

    _tableV.hidden =NO;

    [_tableVreloadData];

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    returnflag ==1 ?array.count:array2.count;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    switch (flag) {

        case1:

            

            [_ScansetTitle:[arrayobjectAtIndex:indexPath.row]forState:(UIControlStateNormal)];


            break;

        case2:

            [_PrintsetTitle:[array2objectAtIndex:indexPath.row]forState:(UIControlStateNormal)];

            break;

        default:

            break;

    }

    _tableV.hidden =YES;

    

}

4、数据开始赋值

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    staticNSString *cellId =@"peripheral";

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellId];

    if (cell ==nil) {

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellId];

    }

    

    switch (flag) {

        case1:

            cell.textLabel.text =array[indexPath.row];

            break;

        case2:

            cell.textLabel.text =array2[indexPath.row];

            break;

            

        default:

            break;

    }

   

    return cell;

}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值