tailieunhanh - iPhone SDK Programming A Beginner’s Guide phần 5

nơi tôi lộn xộn qua các bước và một nơi mà tôi lướt các hướng dẫn. Nó đã giúp tôi có hai màn hình. Trong ví dụ sau, tôi đưa bạn thông qua việc đăng ký và cài đặt một ứng dụng đơn giản trên iPhone của tôi. | Chapter 9 UINavigationBar and UINavigationController 177 Listing 9-10 import implementation SecondViewController - IBAction popSecondView self dismissModalViewControllerAnimated YES - void dealloc super dealloc @end 10. Open and connect the button to the showDetails action. 11. Open and add a navigation bar to the view s canvas just below the view s status bar. Also add a bar button item to the newly added navigation bar. 12. Change the navigation bar s style to Black Translucent Figure 9-18 . Save and close the nib. Figure 9-18 Changing to Black Translucent continued 178 iPhone SDK Programming A Beginner s Guide 13. Connect the newly added bar button item to the File s Owner popSecondView Action. 14. Save and exit Interface Builder. 15. Build and run the application. Refer to FirstViewController in Listing 9-8. The first problem with trying to duplicate the Utility Application template s results is how to make the navigation bar invisible on the first view but visible on the second view. Adding the following line to the viewWillAppear method in FirstViewController accomplishes the invisible visible requirement and ensures the navigation bar is hidden on the first view. setNavigationBarHidden YES animated NO The showDetails method is the action connected to the First View s info button. When you click the info button it invokes showDetails . Note that when the navigation controller pops the second view from the stack the first view s viewWillAppear is invoked ensuring the navigation bar is again hidden. More on the UINavigationController You are not limited to pushing items onto a stack. You can also pop items off the stack. You can also modify the navigation bar hiding elements adding new ones and making other modifications. Pushing and Popping You pop view controllers from a stack using the method popViewControllerAnimated . This method pops .