IOS开发之下拉列表控件开发

本文介绍了一种自定义下拉列表控件的实现方式,通过创建`Commbox`类,集成`UITableViewDataSource`、`UITableViewDelegate`和`UITextFieldDelegate`协议,实现了在iOS应用中显示下拉列表的功能。代码示例详细展示了如何初始化和操作这个自定义控件,包括列表的显示和隐藏、数据源处理、单元格定制等。
摘要由CSDN通过智能技术生成

效果

[html]  view plain copy
  1. //  Commbox.h    
  2. //  CommboxDemo    
  3. //    
  4. //  Created by xuqiang on 13-9-27.    
  5. //  Copyright (c) 2013年 xuqiang. All rights reserved.    
  6. //    
  7.     
  8. #import <UIKit/UIKit.h>    
  9.     
  10. @interface Commbox : UIView<UITableViewDataSource, UITableViewDelegate,UITextFieldDelegate>    
  11. {    
  12.     UITableView *tv;//下拉列表    
  13.     NSMutableArray *tableArray;//下拉列表数据    
  14.     UITextField *textField;//文本输入框    
  15.     BOOL showList;//是否弹出下拉列表    
  16.     CGFloat tabheight;//table下拉列表的高度    
  17.     CGFloat frameHeight;//frame的高度    
  18. }    
  19.     
  20. @property (nonatomic,retain) UITableView *tv;    
  21. @property (nonatomic,retain) NSArray *tableArray;    
  22. @property (nonatomic,retain) UITextField *textField;    
  23.     
  24. @end    
  25. </pre><br><br>    
  26. [html] view plaincopy  
  27. <pre name="code" class="html">//    
  28. //  Commbox.m    
  29. //  CommboxDemo    
  30. //    
  31. //  Created by xuqiang on 13-9-27.    
  32. //  Copyright (c) 2013年 xuqiang. All rights reserved.    
  33. //    
  34.     
  35. #import "Commbox.h"    
  36.     
  37. @implementation Commbox    
  38. @synthesize tv,tableArray,textField;    
  39.     
  40. - (id)initWithFrame:(CGRect)frame    
  41. {    
  42.         
  43.     if (frame.size.height<200) {    
  44.         frameHeight = 200;    
  45.     }else{    
  46.         
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值