ios下拉菜单tableview的实现

 ActivitiesViewController.h里面

{

    BOOL bol;//判定优惠券下拉菜单的开关

}

@property(retain,nonatomic)NSMutableArray *array;

@property (retain, nonatomic)UIView *aselectview;

@property(retain,nonatomic)UITableView *tableViewFree;   

ActivitiesViewController.m里面 

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.array = [NSMutableArray arrayWithObjects:@"餐饮",@"休闲",@"娱乐",@"酒店",@"旅游",@"家居",@"家电",@"服装",@"健身",@"婚嫁",@"美妆",@"其他",nil];//优惠券下拉菜单
         UIView  *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, 320, [UIScreen mainScreen].bounds.size.height-40)];

    aView.backgroundColor=[UIColor colorWithRed:green:blue:alpha:0.6];

    self.aselectview=aView;

    [self.view addSubview:aView];
//创建一个表视图

    UITableView  *atableViewfree=[[UITableView alloc]initWithFrame:CGRectMake(160, 0, 160, [UIScreen mainScreen].bounds.size.height-40) style:UITableViewStylePlain];

    atableViewfree.dataSource=self;

    atableViewfree.delegate=self;

    [self.aselectview addSubview:atableViewfree];

    self.tableViewFree=atableViewfree;


    bol=NO;
        self.aselectview.hidden=YES;

 


点击按钮(已经设置过tag)的时候触发的事件

if (bol==NO) {

    bol=YES;
       self.aselectview.hidden=NO; 

} else {

    bol=NO;

       self.aselectview.hidden=YES;

}

      
//表视图判断是哪一个,这是关键
 

//一个组里面的行数

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

    if (tableView==self.tableView) {

       

    } else {

        return self.array.count;

    }

}

//加载行

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

    static  NSString *identify=@"news";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identify];

    if (cell==nil) {

        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:identify];

        cell.selectionStyle=UITableViewCellSelectionStyleNone;

    }

    if (tableView==self.tableView) {

        

    } else {

        cell.textLabel.text=[self.array objectAtIndex:indexPath.row];

    }

    return cell;

}

 

 

//行高

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (tableView==self.tableView) {

 

    } else {

        return 44;

    }

}

//选中一行的时候

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

    //跳转到详细的视图控制器

    if (tableView==self.tableView) {

        

    } else {

        bol=NO;

               self.aselectview.hidden=YES;

              //下面刷新数据

 

    }

    //取消选中的行

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    

    

}

 

 

 



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。