American Mission HD (7)-Add Cancel Search button

Source: Internet
Author: User

Djselectcityviewcontroller.m

#pragmaMark-uisearchbar Proxy method/** Searchbar start editing*/- (void) Searchbartextdidbeginediting: (Uisearchbar *) Searchbar {//Hide Navigation bar[Self.navigationcontroller Setnavigationbarhidden:yes Animated:yes]; //Show MatteUIView *cover =[[UIView alloc] init]; Cover.backgroundcolor=[Uicolor Blackcolor]; Cover.alpha=0.2; Cover.frame=Self.cityTableView.frame; Cover.tag=Djcovertag; //since UIView is not uicontrol, there is no Addtarget method, you can use UITapGestureRecognizer instead//Remove the first responder when Conver is clicked[cover Addgesturerecognizer:[[uitapgesturerecognizer alloc] initwithtarget:searchbar action: @selector (    Resignfirstresponder)];    [Self.view Addsubview:cover]; //Set current search box background to highlight background[Searchbar setbackgroundimage:[uiimage imagenamed:@"Bg_login_textfield_hl"]]; //Show Cancel button[Searchbar Setshowscancelbutton:yes Animated:yes]; }/** Searchbar End Edit*/- (void) Searchbartextdidendediting: (Uisearchbar *) Searchbar {//Show navigation bar[Self.navigationcontroller setnavigationbarhidden:no Animated:yes]; //Hide Masks[[Self.view Viewwithtag:djcovertag] removefromsuperview]; //Set the current search box background to a normal background[Searchbar setbackgroundimage:[uiimage imagenamed:@"Bg_login_textfield"]]; //Hide Cancel button[Searchbar setshowscancelbutton:no Animated:yes]; }/** This method is called when the Cancel button above the Searchbar is clicked*/- (void) searchbarcancelbuttonclicked: (Uisearchbar *) Searchbar {//Hide Keyboard[Searchbar Resignfirstresponder]; //empty the input contentSearchbar.text =@"";}/** Call this method when the text inside the Searchbar changes*/- (void) Searchbar: (Uisearchbar *) Searchbar textdidchange: (NSString *) SearchText {UIView*cover =[Self.view Viewwithtag:djcovertag]; if(searchtext.length) {//the current input is not empty        if(Cover.subviews.count <=0) {Cover.alpha=1.0; Self.searchResultVC.view.frame= CGRectMake (0,0, Cover.width, cover.height);        [Cover AddSubview:self.searchResultVC.view]; }    } Else{//the current input is empty[Self.searchResultVC.view Removefromsuperview]; Cover.alpha=0.2; }    }

American Mission HD (7)-Add Cancel Search button

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.