ios-请问下我的这个下拉菜单,一拉出来就被别的覆盖掉了,怎么办?

问题描述

请问下我的这个下拉菜单,一拉出来就被别的覆盖掉了,怎么办?

我想让他点出来的时候在最上面

解决方案

下面的是我的代码
//设置商品分类的子分类
_comboBoxClass = [[ComboBoxView alloc] initWithFrame:CGRectMake(180, 120, 100 , 130)];
_comboBoxClass.comboBoxDatasource = comboBoxDatasource;
_comboBoxClass.backgroundColor = [UIColor clearColor];
[ _comboBoxClass setContent:[comboBoxDatasource objectAtIndex:0]];
[self.view addSubview: _comboBoxClass];

  • (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
    [self initVariables];
    [self initCompentWithFrame:frame];
    }
    return self;
    }

#pragma mark -
#pragma mark custom methods

  • (void)initVariables {
    _showComboBox = NO;
    }
  • (void)initCompentWithFrame:(CGRect)frame {
    _selectContentLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 60, 25)];
    _selectContentLabel.font = [UIFont systemFontOfSize:14.0f];
    _selectContentLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_selectContentLabel];

    _pulldownButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_pulldownButton setFrame:CGRectMake(frame.size.width - 25, 0, 25, 25)];
    [_pulldownButton setBackgroundImage:[UIImage imageNamed:@"list_ico_d"] forState:UIControlStateNormal];
    [_pulldownButton addTarget:self action:@selector(pulldownButtonWasClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_pulldownButton];

    _hiddenButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_hiddenButton setFrame:CGRectMake(0, 0, frame.size.width - 25, 25)];
    _hiddenButton.backgroundColor = [UIColor clearColor];
    [_hiddenButton addTarget:self action:@selector(pulldownButtonWasClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_hiddenButton];

    _comboBoxTableView = [[UITableView alloc] initWithFrame:CGRectMake(1, 26, frame.size.width -2, frame.size.height - 27)];
    _comboBoxTableView.dataSource = self;
    _comboBoxTableView.delegate = self;
    _comboBoxTableView.backgroundColor = [UIColor clearColor];
    _comboBoxTableView.separatorColor = [UIColor blackColor];
    _comboBoxTableView.hidden = YES;
    [self addSubview:_comboBoxTableView];

}

  • (void)setContent:(NSString *)content {
    _selectContentLabel.text = content;
    }
  • (void)show {
    _comboBoxTableView.hidden = NO;
    _showComboBox = YES;
    [self setNeedsDisplay];
    }
  • (void)hidden {
    _comboBoxTableView.hidden = YES;
    _showComboBox = NO;
    [self setNeedsDisplay];
    }

#pragma mark -
#pragma mark custom event methods

  • (void)pulldownButtonWasClicked:(id)sender {
    if (_showComboBox == YES) {
    [self hidden];
    }else {
    [self show];
    }
    }

#pragma mark -
#pragma mark UITableViewDelegate and UITableViewDatasource methods

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_comboBoxDatasource count];
    }
  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"ListCellIdentifier";
    UITableViewCell *cell = [_comboBoxTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ; }
    cell.textLabel.text = (NSString *)[_comboBoxDatasource objectAtIndex:indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:13.0f];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
    }
    //设置tableview的数据靠左
    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    { [cell setSeparatorInset:UIEdgeInsetsZero]; }
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)])
    { [cell setPreservesSuperviewLayoutMargins:NO]; }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    { [cell setLayoutMargins:UIEdgeInsetsZero]; }}

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 25.0f;
    }
  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self hidden];
    _selectContentLabel.text = (NSString *)[_comboBoxDatasource objectAtIndex:indexPath.row];
    }
  • (void)drawListFrameWithFrame:(CGRect)frame withContext:(CGContextRef)context {
    CGContextSetLineWidth(context, 1.0f);
    CGContextSetRGBStrokeColor(context, 0.0f, 0.0f, 0.0f, 1.0f);
    if (_showComboBox == YES) {
    CGContextAddRect(context, CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height));

    }else {
    CGContextAddRect(context, CGRectMake(0.0f, 0.0f, frame.size.width, 25.0f));
    }
    CGContextDrawPath(context, kCGPathStroke);
    CGContextMoveToPoint(context, 0.0f, 25.0f);
    CGContextAddLineToPoint(context, frame.size.width, 25.0f);
    CGContextMoveToPoint(context, frame.size.width - 25, 0);
    CGContextAddLineToPoint(context, frame.size.width - 25, 25.0f);

    CGContextStrokePath(context);
    }

#pragma mark -
#pragma mark drawRect methods

  • (void)drawRect:(CGRect)rect {
    [self drawListFrameWithFrame:self.frame withContext:UIGraphicsGetCurrentContext()];
    }

#pragma mark -
#pragma mark dealloc memery methods

@end

解决方案二:

这是先添加下拉,再加3,下拉就在3下面了,试试点击后添加到view,选择后隐藏

时间: 2024-09-20 00:22:04

ios-请问下我的这个下拉菜单,一拉出来就被别的覆盖掉了,怎么办?的相关文章

请问怎样实现“Combobox下拉菜单变化后文本框的数组会跟着变化”

问题描述 请问各位高手怎样实现"Combobox下拉菜单变化后文本框的数组会跟着变化"?举例:Combobox控件菜单内容分别为"kg/s","kg/min","kg/h",当单位变化时,文本框里的数值会随着单位的改变而改变. 解决方案 解决方案二:在选项变化的事件里写代码改变文本框的值解决方案三:引用1楼xdashewan的回复: 在选项变化的事件里写代码改变文本框的值 请告诉我代码怎么写谢谢解决方案四:uphttp://c

请问C#怎样做一个下拉菜单呢?先谢谢大家

问题描述 请问C#怎样做一个下拉菜单呢? 解决方案 解决方案二:用js写的菜单网上有很多的解决方案三:WinForm的拖个MenuStrip控件上来然后键如文本,双击进去,填写代码就OK了解决方案四:UP解决方案五:引用2楼mengyangchao的回复: WinForm的拖个MenuStrip控件上来然后键如文本,双击进去,填写代码就OK了 解决方案六:引用4楼taiyangyu119的回复: 引用2楼mengyangchao的回复:WinForm的拖个MenuStrip控件上来然后键如文本,

浏览器 office2010-安装了office2010后,关于日期的下拉菜单出问题了!

问题描述 安装了office2010后,关于日期的下拉菜单出问题了! 把office更新为office2010后,在使用IE内核的浏览器登陆"商务部二手车交易市场"管理系统中,在点开一个表单填写日期的过程中发现了一个问题,那是一个日期下拉菜单,点开"年"的下拉菜单可以选择,但是在点开"月""日"的下拉菜单时却出现错误,没法显示下拉菜单,经观察所有装有office2010的电脑都有这种现象出现,而2007版本则没有这样的问题,或

jQuery点击弹出下拉菜单

<title>导航--点击弹出内容</title> <style type="text/css"> .navgation{margin:0;padding:0;list-style-type:none;position:relative;} .navgation li {float:left;} .navgation a{padding:3px 6px;background-color:orange;color:white; text-decorat

stylesheet-bootstrap中的导航中java为何在360浏览器java下拉菜单点了没反应

问题描述 bootstrap中的导航中java为何在360浏览器java下拉菜单点了没反应 <!DOCTYPE html> Bootstrap 实例 - 带有下拉菜单的标签 带有下拉菜单的标签 Home SVN iOS VB.Net Java Swing jMeter EJB 分离的链接 PHP 以下是显示的图片 解决方案 电脑感染了360等非法流氓软件 解决方案二: 有可能是浏览器禁用了js--换个浏览器--比如谷歌火狐--

JAVA中在文本框中输入字符后如何在弹出下拉菜单中出现对应的选项,急求各位大师。

问题描述 JAVA中在文本框中输入字符后如何在弹出下拉菜单中出现对应的选项,急求各位大师. 如何1是电汇,2是信用证.当我在文本框中输入1后,自动弹出下拉菜单:1 电汇. 请说的详细些,这问题真的困扰我很久了.谢谢各位啦. 解决方案 能不能把问题描述的更详细点 输入1 对应的选项 电汇..是从数据库中查询的 还是只是前台的一个效果 解决方案二: 是不是类似于搜索引擎那种,比如百度一样,输入一个三国下面会显示出三国******什么的. 解决方案三: 你说的是自动补全吧,如果是输入框,必须监听输入状

Android仿美团分类下拉菜单实例代码_Android

本文实例为大家分享了Android仿美团下拉菜单的实现代码,分类进行选择,供大家参考,具体内容如下 效果图 操作平台 AS2.0 第三方框架:butterknife build.gradle dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' compile

jsp中根据下拉菜单的值进行查询

问题描述 jsp中根据下拉菜单的值进行查询 当选择一个起点时,如何获得起点编号,求帮助 这是数据库中的表 解决方案 可以给下拉列表添加一个点击事件,把当前对象的ID传给后台查询出起点的编号,然后显示在对应的起点编号的input中 解决方案二: 请问可以说的详细一点吗,代码可以帮我写一下吗,,不太懂 解决方案三: 生成jsp时,将你的数据库表中的ID和下拉列表的选项对应起来,为每个对应的项赋予一个_id属性,这样生成的html就如下所示: <select id="mySelect"

select-关于js中点击下拉菜单,为什么失效?

问题描述 关于js中点击下拉菜单,为什么失效? className="com.edu.dk.portal.app.polaris.common.domain.RootLawType" value="${rootLawType}">/neptune:select 创建了这样一个下拉框,在某些页面能够使用,但在某些页面又失效.请问是哪里出了点问题.