真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

[IOS]網(wǎng)絡(luò)操作+圖片的下載和讀取+json數(shù)據(jù)讀取

如何讀取沙盒中的文件,和保存網(wǎng)絡(luò)資源到沙盒中?

創(chuàng)新互聯(lián)公司專注于織金企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),商城系統(tǒng)網(wǎng)站開發(fā)??椊鹁W(wǎng)站建設(shè)公司,為織金等地區(qū)提供建站服務(wù)。全流程按需設(shè)計,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)

-(NSString *)dataFilePath:(NSString*)fileName

{

   NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

    

    NSString *document=[paths objectAtIndex:0];

    

   return [documentstringByAppendingPathComponent:fileName];

}


-(void)connectionDidFinishLoading:(NSURLConnection *)connection

   //可以下載圖片

    [self.datawriteToFile:[selfdataFilePath:@"image.jpg"]atomically:YES];

    self.webView.hidden =YES;

   //將沙盒中的圖片加載到界面中

    NSString *path = [selfdataFilePath:@"image.jpg"];

   UIImage *imag = [[UIImagealloc]initWithContentsOfFile:path];

   UIImageView *img = [[UIImageViewalloc]initWithImage:imag];

    CGRect rect = CGRectMake(0,0,320,460);

    img.frame = rect;

    [self.viewaddSubview:img];

}


進入主題,接下來我要實現(xiàn)三個功能:

1.訪問網(wǎng)頁

2.從網(wǎng)上加載圖片資源到本地

3.發(fā)送get請求獲取到天氣預(yù)報的接口,然后保存到本地接著是json解析

功能設(shè)計:

1.webView的使用

PageViewController.h:

#import   @interface PageViewController : UIViewController @property (retain, nonatomic) IBOutlet UIWebView *webView; - (IBAction)GoClick:(id)sender; @property (retain, nonatomic) IBOutlet UITextField *txtUrl; - (IBAction)resignBoardClick:(id)sender; @property(retain,nonatomic)NSURL *url; @property(nonatomic,retain)UIAlertView *alert; @end

PageViewController.m:

// //  PageViewController.m //  地圖+網(wǎng)絡(luò) // //  Created by 丁小未 on 13-8-27. //  Copyright (c) 2013年 dingxiaowei. All rights reserved. //  #import "PageViewController.h"  @interface PageViewController ()  @end  @implementation PageViewController  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];     if (self) {         self.title = @"頁面";     }     return self; }  -(void)pageLoad1:(NSURL *)url {     NSURLRequest *request = [NSURLRequest requestWithURL:url];     [self.webView loadRequest:request]; }  - (void)viewDidLoad {     [super viewDidLoad];     self.url = [NSURL URLWithString:@"http://www.baidu.com"];     NSURLRequest *request = [NSURLRequest requestWithURL:self.url];     [self pageLoad1:self.url];  }  -(void)webViewDidFinishLoad:(UIWebView *)webView {     [self.alert dismissWithClickedButtonIndex:0 animated:YES]; }  -(void)webViewDidStartLoad:(UIWebView *)webView {     self.alert = [[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];     [self.alert show];          UIActivityIndicatorView *aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];     aiv.center = CGPointMake(self.alert.bounds.size.width/2, self.alert.bounds.size.height/2);     [aiv startAnimating];     [self.alert addSubview:aiv]; }  - (void)dealloc {     [_webView release];     [_url release];     [_txtUrl release];     [_alert release];     [super dealloc]; } - (IBAction)GoClick:(id)sender {     [self.txtUrl resignFirstResponder];     if (self.txtUrl.text != nil) {         self.url = [NSURL URLWithString:self.txtUrl.text];         [self pageLoad1:self.url];     }     else     {         self.alert = [[UIAlertView alloc] initWithTitle:@"提醒" message:@"地址不能為空" delegate:self cancelButtonTitle:@"OK"otherButtonTitles: nil];         [self.alert show];     } } - (IBAction)resignBoardClick:(id)sender {     [self.txtUrl resignFirstResponder]; } @end 

xib:

[IOS]網(wǎng)絡(luò)操作+圖片的下載和讀取+json數(shù)據(jù)讀取

Demo源文件下載(猛戳)


分享文章:[IOS]網(wǎng)絡(luò)操作+圖片的下載和讀取+json數(shù)據(jù)讀取
本文來源:http://weahome.cn/article/joeoph.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部