iOS base control Uinavigationcontroller, Proxy pass-through value, forward value, reverse pass value
#import<UIKit/UIKit.h>//declaring an agreement@protocolSendvalue<nsobject>//Define a method- (void) Sendbtntitle: (NSString *) title;@end@interfaceFirstviewcontroller:uiviewcontroller//Defining proxies@property (nonatomic, assign)ID<SendValue>Delegate;//to create a property of a forward pass value@property (nonatomic,copy) NSString*Currenttitle;@end
- (void) didbutton{Nsarray*btntitles = [Nsarray arraywithobjects:@"Key One",@"Key Two",@"Key Three", nil]; for(intI=0; i<btntitles.count; i++) {UIButton*BTN =[UIButton Buttonwithtype:uibuttontypesystem]; //Change key font color[btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; [btn Settitle:[btntitles objectatindex:i] forstate:uicontrolstatenormal];
If the caption of the button is the same as the _currenttitle in the property, it is the same as the title of the navigation bar in the root pageif([_currenttitle IsEqualToString:btn.currentTitle]) {
Turn on the selected state btn.selected=YES; Btn.tintcolor=[Uicolor Whitecolor]; } [btn Settitlecolor:[uicolor Redcolor] forstate:uicontrolstateselected]; [Btn addtarget:self Action: @selector (titlebtnclicked:) forcontrolevents:uicontroleventtouchupinside]; Btn.frame= CGRectMake ( the, $+ -*i, self.view.frame.size.width- the, +); Btn.backgroundcolor=[Uicolor Whitecolor]; [Self.view ADDSUBVIEW:BTN]; }}- (void) titlebtnclicked: (UIButton *) btn{NSString*title =Btn.currenttitle;
determine if there is sendbtntitle in the agent : This function
if ([_delegate respondstoselector:@selector(sendbtntitle:)]) {
// agent executes its own sendbtntitle function, the argument is the title
[_delegate sendbtntitle: title];
}
NSLog (@ "%@", title); [Self.navigationcontroller Popviewcontrolleranimated:yes]; }
#import <UIKit/UIKit.h>#define C (a,b,c,d) [Uicolor colorwithred:a/255.0 green:b/255.0 Blue:c /255.0 alpha:d/255.0]#define IMG (name) [UIImage imagenamed:name]#import" FirstViewController.h"// Attach the agreement @interface rootviewcontroller: uiviewcontroller<sendvalue>@end
- (void) btnclicked{Firstviewcontroller*first =[[Firstviewcontroller alloc] init]; //Pass the Navigationitem.title of the current page in//forward Pass ValueFirst.currenttitle =Self.navigationItem.title; //Specifies the proxy as a pointer to the current Rootviewcontroller classFirst.Delegate=Self ; [Self.navigationcontroller Pushviewcontroller:first animated:yes];}//ways to implement protocol definitions- (void) Sendbtntitle: (NSString *) title{Self.navigationItem.title=title;}
Page Pass Value:
The forward value utilization is the value of the attribute;
The value of the proxy is used in the inverse transmission.
Property Passing Value: If the value is passed from page A to page B, the attribute is declared in page B, and the property of page B is assigned to the attribute in the Jump event on page A;
Returning the previous page from the latter page does not perform the Loadview and Viewdidload methods of the previous page, but instead executes the Viewwillappear method, because the Loadview and Viewdidload methods are loaded into memory. When returned from the latter page, the previous page has been loaded into memory, so do not have to load again, so do not execute the Loadview and Viewdidload methods;
Proxy value: As with the proxy design mode, follow the four steps to set up the agent and follow the Protocol,
/*
1, definition Protocol (BAOMUPROTOCOL)
2, following the class of the agreement (nurse)
3. Define the class that requires the proxy (mother)
4. Establishing a relationship (a member variable that defines a proxy type in mother)
*/
Pass-through values in iOS base control Uinavigationcontroller