[Reprinted] tips for iPhone uinavigationcontroller

Source: Internet
Author: User

From http://www.cnblogs.com/pipizhu/archive/2011/05/30/2063235.html

 

 1  , Create and use a uinavigationcontroller

Uinavigationcontroller * Anav = [[Uinavigationcontroller alloc] init];
Add a view. Otherwise, the navigation bar is meaningless.

Uiviewcontroller * Aview = [[Uiview alloc] initwithnibname :( * XIB file name * )]; [Anav pushviewcontroller: aview animated: No]; // The first view in the navigation bar should not be animated
2 , Set the left and right buttons in the navigation bar:
As I said, the button for setting the navigation bar is not to set the navigation bar itself, but to the View Controller in the navigation bar. For example, we set aview.

Set its title:

Aview. Title = @" Title " ; // Configure a button. Here I am from my Buddhist scriptures.CodeUibarbuttonitem * callmodalviewbutton = [[uibarbuttonitem alloc] initwithtitle: @ "" style: uibarbuttonitemstylebordered target: Self action: @ selector (callmodallist)]; self. navigationitem. leftbarbuttonitem = callmodalviewbutton; [callmodalviewbutton release]; // Because the local view will rehold it, We can release it.
As you can see, it is quite simple.

3 , Other common methods and attributes:

Local view. navigationitem. leftbarbuttonitem // Local Project view on the left sidebar. navigationitem. rightbarbuttonitem // Local view of the right sidebar. navigationitem. backbarbuttonitem // Local Project view in the back bar. navigationitem. hidesbackbutton // Hide the back button (yes or no)
In the view's viewwillappear: method, add:


[Self. tableview reloaddata];

Does not work. viewwillappear: This method is not called at all.

Later, we found that the viewwillappear method was ineffective after uinavigationcontroller was used. We can achieve this goal only by using the-navigationcontroller: willshowviewcontroller: animated: Method of uinavigationcontroller.

To do this, you must perform the following steps:

1 . Set proxy class


Nav. Delegate = Self;

2 The proxy class implements uinavigationcontrollerdelegate Protocol
3 . Add-navigationcontroller: willshowviewcontroller: animated: Method to the proxy class.

For example:






- ( Void ) Navigationcontroller :( uinavigationcontroller * ) Navigationcontroller willshowviewcontroller :( uiviewcontroller * ) Viewcontroller animated :( bool) animated {
[Self. mytableview reloaddata];
}

Pushviewcontroller: viewcontroller animated: bool

(Load View Controller)
-Add and display the specified view controller, followed by: whether the view is animated

Popviewcontrolleranimated: bool

(The current view controller is displayed)
-The previous view is displayed on the left.

Poptoviewcontroller: viewcontroller animated: bool

(To the specified View Controller)
-Return to the specified view controller, that is, not only one

Poptorootviewcontrolleranimated: bool

(To the Root View Controller)
-For example, if you have a "home" key, this method may be implemented.

Setnavigationbarhidden: bool animated: bool

(Set whether the navigation bar is displayed)
-If you want to hide the navigation bar, this is the place. See the Picasa webapp Style


Now pushviewcontroller: animated: different page conversion effects



1 The first thing to note is that the default animation of pushviewcontroller is not used. Therefore, when calling this function, set the animation to No.

2 . Use a common catransition to achieve the conversion effect. The Code is as follows:

Catransition * Animation = [Catransition animation];

[Animation setduration: 0.3 ];

[Animation settype: kcatransitionmovein];

[Animation setsubtype: kcatransitionfromtop];

[Animation settimingfunction: [camediatimingfunction functionwithname: kcamediatimingfunctiondefault];



[Self. navigationcontroller pushviewcontroller: m_poseaddissueviewcontroller animated: No];



[Self. navigationcontroller. View. layer addanimation: animation forkey: Nil];

 

 

 

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.