码迷,mamicode.com
首页 > 移动开发 > 详细

ios中,在SearchBar里面搜索内容,可根据内容来查找所需的信息资源,可获得SearchBar中的内容

时间:2014-07-16 21:26:11      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   art   for   io   

贴一段我很久以前写的小demo,你们就明白了,是把textField套在alertView里的
@interface ViewController : UIViewController <UIAlertViewDelegate, UITextFieldDelegate>{
UILabel *la;
UITextField *myTextField;
}

@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];

la = [[UILabel alloc] init];
la.Frame = CGRectMake(10, 150,300,30);
la.backgroundColor = [UIColor clearColor];
la.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
la.text = @"initLabel";
la.textAlignment = UITextAlignmentCenter;
la.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.75f];
la.shadowOffset = CGSizeMake(0.0f, 5.0f);

la.textColor = [UIColor greenColor];

[self.view addSubview:la];

UIButton *alartBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
alartBtn.frame = CGRectMake(110, 50, 50, 50);
alartBtn.backgroundColor = [UIColor clearColor];
[alartBtn setTitle:@"alart" forState:UIControlStateNormal];
[alartBtn addTarget:self action:@selector(alartShow:) forControlEvents:UIControlEventTouchUpInside];
[alartBtn setAlpha:1.0];
[self.view addSubview:alartBtn];

}
-(void)alartShow:(id)sender{

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@" " delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];

myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];

[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[myTextField setDelegate:self];

[myTextField addTarget:self action:@selector(onTextFieldChanged:forEvent:) forControlEvents:UIControlEventEditingChanged];

NSLog(@"myTextField.text:%@", myTextField.text);

}

- (void)alertView: (UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
{

NSLog(@"%@", myTextField.text);
la.text = myTextField.text;

}
}

- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex == [alert cancelButtonIndex]) {
close(0);
}

}

- (void) onTextFieldChanged:(id)sender forEvent:(UIEvent *)event{

NSLog(@"%@", myTextField.text);
}
摘出来的,大概意思应该已经有了,有用的自己在看下。。。欢迎技术交流,彼此进步。。谢谢。。

ios中,在SearchBar里面搜索内容,可根据内容来查找所需的信息资源,可获得SearchBar中的内容,布布扣,bubuko.com

ios中,在SearchBar里面搜索内容,可根据内容来查找所需的信息资源,可获得SearchBar中的内容

标签:style   color   os   art   for   io   

原文地址:http://www.cnblogs.com/Wild-orangutans/p/3836034.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!