三十三:IOS多視圖跳轉(zhuǎn)方法
第一種:跳轉(zhuǎn):[self PResentModalViewController:control animated:YES];返回:[self dismissModalViewControllerAnimated:YES];第二種:跳轉(zhuǎn):[self.navigationController pushViewController:subTableViewController animated:YES];返回:[self.navigationController popViewControllerAnimated:YES];第三種:自己控制: [self.view addSubview:<#(UIView *)#>] [self.view removeFromSuperview];注意:pushViewController和popViewController進(jìn)行視圖間的切換,就必須要求當(dāng)前視圖是個(gè)NavigationController,
第四種:
// 根據(jù)Segue ID 執(zhí)行跳轉(zhuǎn)
[self performSegueWithIdentifier:@"contactList" sender:nil];
三十四:presentModalViewController與dismissModalViewControllerAnimated注意事項(xiàng)
在實(shí)際開發(fā)中,如果要彈出視圖:我們常用到presentModalViewController方法和dismissModalViewControllerAnimated方法。presentModalViewController:彈出視圖dismissModalViewControllerAnimated:隱藏視圖彈出視圖:FeedbackViewController *feedbackViewController = [[FeedbackViewController alloc]initWithNibName:@"FeedbackViewController" bundle:nil]; UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:feedbackViewController]; [self presentModalViewController:navigationController animated:YES];隱藏視圖:[self dismissModalViewControllerAnimated:YES];關(guān)于這兩個(gè)方法的幾點(diǎn)說(shuō)明:1.iphone上彈出/隱藏 視圖時(shí),使用為全屏模式2.搞清楚誰(shuí)是presenting,誰(shuí)是presented如果A彈出B,那么A為presenting,B為presented。3.隱藏視圖的策略我們假如A彈出B就是說(shuō),A負(fù)責(zé)隱藏B;如果我們?cè)贐中調(diào)用dismissModalViewControllerAnimated方法,那么編譯器,自動(dòng)將消息發(fā)送給A。等等,什么消息?簡(jiǎn)單的理解,當(dāng)執(zhí)行presentModalViewController:方法:在A彈出B時(shí):執(zhí)行A的viewWillDisappear方法,通知B執(zhí)行自己的viewWillAppear方法和viewDidAppear執(zhí)行A的viewDidDisappear方法當(dāng)執(zhí)行dismissModalViewControllerAnimated方法:隱藏B時(shí):執(zhí)行B的viewWillDisappear通知A執(zhí)行自己的viewWillAppear方法和viewDidAppear方法執(zhí)行B的viewDidDisappear方法以下我做了個(gè)測(cè)試來(lái)輸出一輪AB切換: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----當(dāng)我們信心慢慢,慶幸我們可以了解了這兩個(gè)方法時(shí),悲劇發(fā)生了:4.蘋果官方已經(jīng)把這兩個(gè)方法 Deprecated in iOS 6.0. 了- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;- (void)dismissModalViewControllerAnimated:(BOOL)animated;取而代之的是:[self presentViewController:navigationController animated:YES completion:^(void){ // Code }];[self dismissViewControllerAnimated:YES completion:^(void){ // Code }];新接口的差別是提供了一個(gè)參數(shù),允許你傳入一個(gè)block。這個(gè)block的回調(diào)方法在VC的viewWillDisappear方法后調(diào)用。也就是被隱藏的VC對(duì)象被釋放后運(yùn)行回調(diào)。這樣做的好處:可以方便做多個(gè)UI效果之間的銜接和轉(zhuǎn)換。
三十五:視圖跳載的幾種動(dòng)畫
BaiDuViewController* baiduController=[mainStoryboard instantiateViewControllerWithIdentifier:@"baiduStoryboard"]; baiduController.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; [self presentViewController:baiduController animated:YES completion:^{ }];
三十六:JSONKit的使用方法
json開源的類庫(kù)有很多,其中JSONKit庫(kù)是非常簡(jiǎn)單易用而且效率又比較高的,重要的JSONKit適用于ios 5.0以下的版本。下載地址:https://github.com/johnezang/JSONKit使用JSONKit庫(kù)來(lái)解析json文件,只需要下載JSONKit.h 和JSONKit.m添加到工程中,設(shè)置支持arc,在項(xiàng)目中build phases中的compile sources,選擇jsonkit.m然后確認(rèn)鍵輸入-fno-objc-arc #import "JSONKit.h"//假設(shè) strJson 是網(wǎng)絡(luò)上接收到的 json 字符串,NSString *strJson = @"[{/"Id/": 1,/"BrandName/": /"愛馬仕/" },{/"Id/": 2,/"BrandName/": /"安娜蘇/"}]"; 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); }字典arrlist便是解析好的json文件了。JSONKit庫(kù)也可以用來(lái)生成json文件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];另一個(gè),其中Operation.responseString就是下面那串json字符串,通過(guò)它進(jìn)行解析: NSDictionary* resultDictionary=[operation.responseString objectFromJSONStringWithParSEOptions:JKParseOptionLooseUnicode]; NSLog(@"%@ Items Found!",[resultDictionary objectForKey:@"weatherinfo"]); //{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"3","WD":"北風(fēng)","WS":"3級(jí)","SD":"24%","WSE":"3","time":"11:25","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB","njd":"暫無(wú)實(shí)況","qy":"1028"}} self.weaLableInfo.text=[NSString stringWithFormat:@"城市:%@,溫度:%@",[[resultDictionary objectForKey:@"weatherinfo"]objectForKey:@"city"],[[resultDictionary objectForKey:@"weatherinfo"]objectForKey:@"temp"]];
三十七:三十五:afnetworking2.0運(yùn)用,結(jié)合json,引入afnetworking文件后,引入頭文件就可以使用,支持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:JKParseOptionLooseUnicode]; NSLog(@"%@ Items Found!",[resultDictionary objectForKey:@"weatherinfo"]); //{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"3","WD":"北風(fēng)","WS":"3級(jí)","SD":"24%","WSE":"3","time":"11:25","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB","njd":"暫無(wú)實(shí)況","qy":"1028"}} self.weaLableInfo.text=[NSString stringWithFormat:@"城市:%@,溫度:%@",[[resultDictionary objectForKey:@"weatherinfo"]objectForKey:@"city"],[[resultDictionary objectForKey:@"weatherinfo"]objectForKey:@"temp"]]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error:%@",error); }]; }帶post參數(shù)到服務(wù)端AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];//申明返回的結(jié)果是json類型manager.responseSerializer = [AFJSONResponseSerializer serializer];//申明請(qǐng)求的數(shù)據(jù)是json類型manager.requestSerializer=[AFJSONRequestSerializer serializer];//如果報(bào)接受類型不一致請(qǐng)?zhí)鎿Q一致text/html或別的manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];//傳入的參數(shù)NSDictionary *parameters = @{@"1":@"XXXX",@"2":@"XXXX",@"3":@"XXXXX"};//你的接口地址NSString *url=@"http://xxxxx";//發(fā)送請(qǐng)求[manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject);} failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error);}];
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注