ios - Emulate searchbar in Calendar app -


i trying emulate search bar in calendar app , finding surprisingly difficult although many people have posed question on , elsewhere , many half answers have been offered. (i need support ios 7).

the main requirements

1) there search bar button.

2) when above button pressed, search bar cancel appears in navigation bar.

to accomplish 1) put bar button item on navigation bar. no problem.

to accomplish 2) hard part.

to search bar display in navigation bar opposed elsewhere supposed set self.searchdisplaycontroller.displayssearchbarinnavigationbar= true here;

i can search bar appear in nav bar without cancel button.

the code show cancel button supposed be:

self.searchdisplaycontroller.searchbar.showscancelbutton = yes; 

this not working in conjunction placing search bar in nav bar.

finally, opposed searchdisplaycontroller, called search bar has property called .hidden. after dragging search bar , search displaycontroller view, i've created outlet property , tried change without success. (changing true false has no apparent effect on output.)

is there out there has created ux can describe steps needed emulate search bar in calendar app in ios 7.0?

the following code illustrate idea. if want use it, have adjust needs, take care orientation changes , add tableview. there constants replaced better.

class viewcontroller: uiviewcontroller, uisearchbardelegate {     let searchbar = uisearchbar()     private var searchbarvisible = false      override func viewdidload() {         super.viewdidload()          searchbar.showscancelbutton = true         searchbar.delegate = self          let height: cgfloat = 44         let window = uiapplication.sharedapplication().keywindow!         self.searchbar.frame = cgrectmake(0, -height, window.frame.width, height)     }      override func viewwilldisappear(animated: bool) {         super.viewwilldisappear(animated)         self.dismisssearchbaranimated(true)     }      func showsearchbaranimated(animated: bool) {         if !searchbarvisible {             let window = uiapplication.sharedapplication().keywindow!             window.addsubview(searchbar)             searchbar.setneedslayout()             let duration = animated ? 0.2 : 0 // 0 executes             self.searchbar.becomefirstresponder()             uiview.animatewithduration(duration) { () -> void in                 self.searchbar.frame = cgrectmake(0, 20, window.frame.width, self.searchbar.frame.height)             }             searchbarvisible = true         }     }      func dismisssearchbaranimated(animated: bool) {         let window = uiapplication.sharedapplication().keywindow!         let duration = animated ? 0.2 : 0 // 0 executes         self.searchbar.resignfirstresponder()         uiview.animatewithduration(duration,             animations: { () -> void in                 self.searchbar.frame = cgrectmake(0, -self.searchbar.frame.height, window.frame.width, self.searchbar.frame.height)             }) {(completed) -> void in                 self.searchbar.removefromsuperview()                 self.searchbarvisible = false         }     }      @ibaction func actionsearchbutton(sender: anyobject) {         self.showsearchbaranimated(true)     }      //mark: - uisearchbardelegate     func searchbar(searchbar: uisearchbar, textdidchange searchtext: string) {         nslog("should search '\(searchtext)'.")     }      func searchbarcancelbuttonclicked(searchbar: uisearchbar) {         self.dismisssearchbaranimated(true)     }      func positionforbar(bar: uibarpositioning) -> uibarposition {         return .topattached     } } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -