【代碼筆記】點擊搜尋按鈕,或放大鏡後都會彈出搜尋方塊,按鈕放大鏡
一, 。
二,工程圖。
三,代碼。
RootViewController.h
#import <UIKit/UIKit.h>#import "CLHSearchBar.h"@interface RootViewController : UIViewController<CLHSearchBarDelegate>@end
RootViewController.m
#import "RootViewController.h"@interface RootViewController ()@end@implementation RootViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor=[UIColor grayColor]; //添加搜尋欄 CLHSearchBar* searchBar = [[CLHSearchBar alloc] initWithFrame:CGRectMake(0, 90, 0, 0) delegate:self]; [self.view addSubview:searchBar];}#pragma -mark -FCSearchBar delegate//按照聊天內容和暱稱進行查詢//點擊搜尋按鈕,或放大鏡後都會彈出搜尋方塊- (void)CLHSearchBarDidSearch:(CLHSearchBar *)clhSearchBar text:(NSString *)text{ NSLog(@"text = %@",text); UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"搜尋按鈕已點擊" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil]; [alert show]; }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}