iphone 模仿百度输入框提示
来源:互联网 发布:算法工程师需要哪些知识 编辑:程序博客网 时间:2024/05/19 04:53
iphone 的UITextField 模仿百度搜索提示,达到输入正确E-mail地址,详细实现如下:
#import <UIKit/UIKit.h>
@interface DemoMailViewController : UIViewController<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource>
{
UITextField *mailTextField;
UITableView *myTableView;
NSMutableArray *promptarray;
NSMutableArray *myArr;
}
@property (nonatomic,retain)IBOutlet UITextField *mailTextField;
@property (nonatomic,retain)IBOutlet UITableView *myTableView;
@property (nonatomic,retain) NSMutableArray *myArr;
-(IBAction) textFieldDoneEditing:(id)sender;
@end
#import "DemoMailViewController.h"
@implementation DemoMailViewController
@synthesize mailTextField,myTableView;
@synthesize myArr;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
myTableView.hidden=YES;
[superviewDidLoad];
}
-(IBAction) textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder];
}
//文本框开始输入的时候
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
self.myArr=[[NSMutableArrayalloc] init];
[mailTextFieldaddTarget:selfaction:@selector(textFieldDidChange:)forControlEvents:UIControlEventEditingChanged];
}
//结束输入的时候
-(void)textFieldDidEndEditing:(UITextField *)textField
{
myTableView.hidden=YES;
}
//显示提示的选项
- (void) textFieldDidChange:(UITextField *) TextField
{
myTableView.hidden=YES;
promptarray=[[NSArrayalloc]initWithObjects:@"@qq.com",@"@163.com",@"@gmail.com",@"@sina.com",@"@foxmail.com",@"@sohu.com",@"@163.com",@"@tom.com",@"@yeah.com",@"@yahoo.com.cn",nil];
[self.myArrremoveAllObjects];
int i;
for(i=0;i<[promptarraycount];i++)
{
NSMutableString *add=[[NSMutableStringalloc] initWithString:TextField.text];
[add appendString:[promptarrayobjectAtIndex:i]];
[self.myArraddObject:add];
}
myTableView.hidden=NO;
[myTableView reloadData];
}
////随便点击外面刷新试图
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[mailTextFieldresignFirstResponder];
}
#pragma mark tableView delegate and dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.myArrcount];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 48;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row=[indexPath row];
static NSString *CellIdentifier =@"Cell";
UITableViewCell *cell = [myTableViewdequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];
}
if (myArr&&[myArrcount])
{
cell.textLabel.text =[myArrobjectAtIndex:row];;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
mailTextField.text = [myArrobjectAtIndex:indexPath.row];
myTableView.hidden=YES;
}
- iphone 模仿百度输入框提示
- c#模仿百度关键词提示
- 模仿百度“您要找的是不是:”提示功能
- 模仿QQ 输入框
- 百度的搜索输入提示
- [百度搜索框Bootstrap模仿]
- 模仿Toast实现提示框
- 模拟谷哥,和百度的输入自动提示框
- 仿百度输入框智能提示的js代码
- 百度地图输入框关键字提示被模态框挡住
- 模仿百度搜索的自动提示功能 高大上
- Jquery 模仿Baidu、Google收索时提示输入结果
- h5键盘遮挡输入框问题 、模仿微信输入框失去焦点时隐藏iphone的软键盘和聚焦时出现输入框
- bootstrap仿百度输入框智能提示(提示信息存在于数据库中)
- ajax(2)实现智能输入提示(类似百度搜索框智能输入)
- 模仿百度API接口搜索框
- ASP.NET实验五:实现输入内容提示的功能(仿google_百度输入框提示)
- 实现输入内容提示的功能(仿google_百度输入框提示)jquery.ui.autocomplete.js插件
- 使用Jakarta Commons Pool处理对象池化(zz)
- unix 常用命令
- 淘宝开店方法流程,如何尽快赚钱
- 构建WCF RESTful service示例
- 《windows核心编程系列》十八谈谈windows钩子
- iphone 模仿百度输入框提示
- VC开发打印机相关API
- 实现类似UC浏览器的菜单
- 身心俱疲
- 网络流基础
- hdu 1165 Eddy's research II
- oracle字符串分割和提取
- 国际化
- Nginx源码分析-事件循环