33: iOS Multi-View Jump method
The first kind: jump: [Self presentmodalviewcontroller:control animated:yes]; return: [Self dismissmodalviewcontrolleranimated:yes]; The second kind: jump: [Self.navigationcontroller pushviewcontroller:subtableviewcontroller Animated:yes]; return: [ Self.navigationcontroller Popviewcontrolleranimated:yes]; Third: Own control: [Self.view addsubview:<# (UIView *) #>] [ Self.view Removefromsuperview]; Note: Pushviewcontroller and Popviewcontroller Switch between views, you must require that the current view is a navigationcontroller,
The fourth type:
Perform a jump based on the segue ID
[Self performseguewithidentifier:@ "contactlist" sender:nil];
34: Presentmodalviewcontroller
Precautions with dismissmodalviewcontrolleranimated
In the actual development, if you want to pop up the view: We often use the Presentmodalviewcontroller method and the Dismissmodalviewcontrolleranimated method. Presentmodalviewcontroller: Pop-up View dismissmodalviewcontrolleranimated: Hide View pop-up view: Feedbackviewcontroller * Feedbackviewcontroller = [[Feedbackviewcontroller alloc]initwithnibname:@ "Feedbackviewcontroller" bundle:nil]; Uinavigationcontroller *navigationcontroller = [[Uinavigationcontroller alloc]initwithrootviewcontroller: Feedbackviewcontroller]; [Self presentmodalviewcontroller:navigationcontroller animated:yes]; Hide view: [Self dismissmodalviewcontrolleranimated : YES]; A few notes on these two methods: 1.iPhone on the pop/Hide view, use for full-screen mode 2. Figure out who is presenting, who is presented if a POPs B, then A is presenting,b for presented. 3. The policy of hiding the view if a pops up B that means, a is responsible for hiding B; If we call the Dismissmodalviewcontrolleranimated method in B, the compiler automatically sends the message to a. Wait, what news? Simple comprehension when executing Presentmodalviewcontroller: Method: When a pops up B: Executes the Viewwilldisappear method of A, Notification B executes its own Viewwillappear method and Viewdidappear executes the Viewdiddisappear method of a when the Dismissmodalviewcontrolleranimated method is executed: Hide B: Execute the Viewwilldisa of B Ppear notification a executes its own Viewwillappear method and Viewdidappear method performs B's ViewdiddiSappear method Below I did a test to output a round AB switchover: a:moreb:feed2012-12-27 14:01:23.666 wtv[1627:11303]- More--viewwilldisappear----2012-12-27 14:01:23.672 wtv[1627:11303]-feed--viewwillappear----2012-12-27 14:01:24.086 wtv[1627:11303]-feed--viewdidappear----2012-12-27 14:01:24.087 wtv[1627:11303]- More--viewdiddisappear----2012-12-27 14:01:25.745 wtv[1627:11303]-feed--viewwilldisappear----2012-12-27 14:01:25.745 wtv[1627:11303]-more--viewwillappear----2012-12-27 14:01:26.156 wtv[1627:11303]- More--viewdidappear----2012-12-27 14:01:26.157 wtv[1627:11303]-feed--viewdiddisappear----When our faith slowly, thankfully we can understand both methods , the tragedy took place: 4. Apple officials have already put these two methods Deprecated in IOS 6.0. -(void) Presentmodalviewcontroller: (Uiviewcontroller *) Modalviewcontroller animated: (BOOL) animated;-(void) Dismissmodalviewcontrolleranimated: (BOOL) animated; instead: [Self presentviewcontroller:navigationcontroller Animated:yes completion:^ (void) {//Code}]; [Self DismissviewcontRolleranimated:yes completion:^ (void) {//Code }]; The difference between the new interface is to provide a parameter that allows you to pass in a block. This block's callback method is called after the VC's Viewwilldisappear method. That is, the hidden VC object is freed after the callback is run. The benefit of doing so is that it makes it easy to make connections and transitions between multiple UI effects.
35: Several animations of the view hop load
baiduviewcontroller* baiducontroller=[mainstoryboard instantiateviewcontrollerwithidentifier:@ "BaiduStoryboard"] ; Baiducontroller.modaltransitionstyle=uimodaltransitionstylefliphorizontal; [Self Presentviewcontroller:baiducontroller animated:yes completion:^{ }];
- Uimodaltransitionstylecoververtical//New view appears from bottom up
- Uimodaltransitionstylefliphorizontal//With the device's long axis as the center of the rollover appears
- Uimodaltransitionstylecrossdissolve//Gradually show
- Uimodaltransitionstylepartialcurl//Original view roll up
36: How to use Jsonkit
There are a lot of JSON open source class libraries, where the Jsonkit library is very easy to use and highly efficient, and the important jsonkit for iOS 5.0. : Https://github.com/johnezang/JSONKit uses Jsonkit library to parse JSON files, just download JSONKit.h and JSONKIT.M add to project, set support arc, build in Project Compile sources in phases, select JSONKIT.M then confirm key input-fno-objc-arc #import "JSONKit.h"//assuming Strjson is a JSON string received on the network, NSString * Strjson = @ "[{\" id\ ": 1,\" brandname\ ": \" hermes \ "},{\" id\ ": 2,\" brandname\ ": \" Anna sui \ "}]"; Nsarray *arrlist=[strjson objectfromjsonstring]; NSLog (@ "%d", [arrlist Count]); for (int i=0; i<[arrlist count]; i++) {nsdictionary *item=[arrlist objectatindex:i]; NSString *brandname=[item objectforkey:@ "brandname"]; NSLog (@ "%@", brandname); The dictionary arrlist is the parsed JSON file. The Jsonkit library can also be used to generate JSON files nsmutabledictionary *jsondic = [Nsmutabledictionary dictionary]; Nsmutabledictionary *alert = [Nsmutabledictionary dictionary]; Nsmutabledictionary *aps = [Nsmutabledictionary dictionary]; [Alert setobject:@ "a msg come!" forkey:@ "body"]; [APS Setobject:alert forkey:@ "alert"]; [APs setobject:@ "3" Forkey:@ "Bage"]; [APs setobject:@ "Def.mp3" forkey:@ "sound"]; [Jsondic setobject:aps forkey:@ "APS"]; NSString *strjson = [Jsondic jsonstring]; another, where operation.responsestring is the following string of JSON, parsed by it: nsdictionary* Resultd Ictionary=[operation.responsestring Objectfromjsonstringwithparseoptions:jkparseoptionlooseunicode]; NSLog (@ "%@ Items found!", [resultdictionary objectforkey:@ "Weatherinfo"]); {"Weatherinfo": {"City": "Beijing", "Cityid": "101010100", "temp": "3", "WD": "North Wind", "WS": "Level 3", "SD": "24%", "WSE": "3", "Time": "11:25", "Isradar": "1", "Radar": "JC_RADAR_AZ9010_JB", "NJD": "No Live", "qy": "1028"}} SELF.WEALABLEINFO.TEXT=[NSSTR ing stringwithformat:@ "Cities:%@, Temperature:%@", [[Resultdictionary objectforkey:@ "Weatherinfo"]objectforkey:@ "City"],[[ Resultdictionary objectforkey:@ "weatherinfo"]objectforkey:@ "temp"];
37:35: afnetworking2.0 use, combined with JSON,
After the introduction of the Afnetworking file, the introduction of the header file can be used to support arc
-(Ibaction) Jsonaction: (Uibarbuttonitem *) Sender {nsstring* weatherurl=[nsstring stringwithformat:@ "%@%@.html", Baseurlstring,self. URLString]; afhttprequestoperationmanager* Manager=[afhttprequestoperationmanager Manager]; Manager.responseSerializer.acceptableContentTypes = [Nsset setwithobject:@ "text/html"]; [Manager Get:weatherurl Parameters:nil success:^ (afhttprequestoperation *operation, id responseobject) {nsdictionary* resultdictionary=[operation.responsestring Objectfromjsonstringwithparseoptions:jkparseoptio Nlooseunicode]; NSLog (@ "%@ Items found!", [resultdictionary objectforkey:@ "Weatherinfo"]); {"Weatherinfo": {"City": "Beijing", "Cityid": "101010100", "temp": "3", "WD": "North Wind", "WS": "Level 3", "SD": "24%", "WSE": "3", "Time": "11:25", "Isradar": "1", "Radar": "JC_RADAR_AZ9010_JB", "NJD": "No Live", "qy": "1028"}} SELF.WEALABLEINFO.TEXT=[NSSTR ing stringwithformat:@ "Cities:%@, Temperature:%@", [[Resultdictionary objectforkey:@ "Weatherinfo"]objectforkey:@ "City"],[[resulTdictionary objectforkey:@ "weatherinfo"]objectforkey:@ "temp"]; } failure:^ (Afhttprequestoperation *operation, Nserror *error) {NSLog (@ "error:%@", error); }]; With post parameter to server Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanager manager];// The result of the declaration returned is the JSON type Manager.responseserializer = [Afjsonresponseserializer serializer];// Declares that the requested data is of the JSON type Manager.requestserializer=[afjsonrequestserializer serializer];//if the accepted type is inconsistent, replace the consistent text/ HTML or other manager.responseSerializer.acceptableContentTypes = [Nsset setwithobject:@ "text/html"];//incoming parameters Nsdictionary *parameters = @{@ "1": @ "xxxx" @ "2": @ "xxxx" @ "3": @ "XXXXX"};//Your interface address nsstring *[email protected] "http://xxxxx"; /Send Request [manager Post:url parameters:parameters success:^ (afhttprequestoperation *operation, id responseobject) {NSLog (@ "JSON:%@", responseobject);} failure:^ (afhttprequestoperation *operation, Nserror *error) {NSLog (@ "error:%@", error);}];
iOS Development Basics-Fragmentation 6