iOS Getting Started note (navigation Controller)

Source: Internet
Author: User

1. Delete the default view controller in the storyboard, and the corresponding. H.M file

2. Drag the Controller object from the object library into the editor (as if two scenes were added)

3. Add two classes, the first to associate a Uinavigationcontroller subclass to the navigation control, and the second to associate the Uiviewcontroller subclass to the root view and other views

(class is its own name, subclassof must select the appropriate parent)

4. After the association is complete, you can change the label of the controller to make it more user-friendly (the label here is not associated with the underlying code)

5. The navigation controller is contacted with the View controller data,

Can be in the navigation controller. h establishes the attribute @property (nonatomic) int pushcount;

, import #import "CountingNAvigationController.H" (which is your named navigation Controller) in the header file of the view controller

In the View Controller class. Access method in M

-(Ibaction) Incrementcount: (ID) sender{

((Countingnavigationcontroller *) Self:      Parentviewcontroller). pushcount++; The Parentviewcontroller property is automatically set as the navigation controller object in the scene managed by the navigation controller

}

In the view controller. It is better to update the labels in the M method viewwillappear:animated because the original scene may be returned after other view push

-(void) Viewwillappear: (BOOL) Animated {
NSString *pushtext;
Pushtext=[[nsstring alloc] initwithformat:@ "%d", ((Countingnavigationcontroller *) self.parentviewcontroller). Pushcount];
Self.countlabel.text=pushtext;
}

Navigation Controller

1. Delete the original view controller and the corresponding class file. H.M

2. Pull the toolbar CONTROLLER from the object library

3. Create the corresponding class, the Uitabbarcontroller sub-class is connected to the Toolbarcontroller

Viewcontroller sub-class connected to common scene controller

4. When adding a scene, connect the option Kahlan controller to the new scene controller, type select releationship-viewcontrollers (option Kahlan Controller will automatically add a toggle)

5. Planning variables

To track 3 different counters, Countingtabbarcontroller contains three properties, each of which is a counter for each scene

Viewcontroller contains two properties, Outputlabel points to a label to display three counter current values, and the second connects Baritem to each scene by selecting Xiangkalan items

To update their badge values

Because there are three different counters, Genericviewcontroller has three operations, each of which triggers a method for the scene (three scenarios common one class control)

Two more methods Updatecounts,updatebadge, update current counter values, and badges (so you don't have to rewrite the same code in each increment)

6. Click the Bottom tab button in the corresponding view, set the properties to select the Custom tab picture, and the corresponding caption. (the corresponding automatically changes in the Main tab controller)

7. Create output, Outputlabel connect to each scene

Baritem connecting to each scene's tab

Required actions

Incrementcountfirst; Connect to the first scene button, update the first scene counter, two or three the same

Because Count operates independently, each button creates its own actions

8. Implementing the Logic

Add 3 properties to Countingtabbarcontroller

@property (nonatomic) int firstcount .... Two or three likewise

Import the file #import "Countingtabbarcontroller in the corresponding child view controller. H

9. Display counter

Declaring method header files in. h

。 Implemented in M

-(void) Updatecounts {
NSString *countstring;
Countstring=[[nsstring Alloc] Initwithformat:
@ "First:%d\nsecond:%d\nthird:%d",
((Countingtabbarcontroller *) self.parentviewcontroller). Firstcount,
((Countingtabbarcontroller *) self.parentviewcontroller). Secondcount,
((Countingtabbarcontroller *) self.parentviewcontroller). Thirdcount];
self.outputlabel.text=countstring;
}
10. Increment of Tab badge value

Declaring method prototypes in. h

. Implemented in M

-(void) Updatebadge {
NSString *badgecount;
int Currentbadge;
Currentbadge=[self.baritem.badgevalue Intvalue]; The Intvalue method converts badgevalue to integers, badgevalue can read the current value of the tab
currentbadge++;
Badgecount=[[nsstring alloc] initwithformat:@ "%d",
Currentbadge];
Self.baritem.badgevalue=badgecount;
}
Badgevalue is a nsstring is not an integer so modify he must perform the corresponding conversion

11. Departure Counter Update

-(Ibaction) Incrementcountfirst: (ID) Sender {
((Countingtabbarcontroller *) self.parentviewcontroller). firstcount++;
[Self Updatebadge];
[Self updatecounts];
}
Two or three likewise

12 Remember to cancel the corresponding property

-(void) viewdidunload
{
[Self setoutputlabel:nil];
[Self setbaritem:nil]; Setbaritem in B will automatically become uppercase.
[Super Viewdidunload];

}

13, remember to update in Viewwillappear

"Self.updatecounts"

iOS Getting Started note (navigation Controller)

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.