IOS开发技术问题总结(一)

一、网络

1、获取指定网址返回的字符串

Dim:

NSURL *url ;//目标网站的地址

NSURLRequest *request;//请求

NSData *response;//回复

NSString *str;//网站返回的字符串

 

request = [NSURLRequest requestWithURL:url]; 

response = [NSURLConnection

sendSynchronousRequest:request

      returningResponse:nil

                              error:nil];

jsonStr = [[NSString alloc]

                       initWithData:response

                              encoding:NSUTF8StringEncoding];

2、从网上读取图片

Dim:

NSString *url;//目标图片的网址,带http://

UIImage *img;//被取出来的图片对象

 

NSURL *imgUrl = [NSURL URLWithString:url];

NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];

img = [UIImage imageWithData:imgData];

 

3、获取UiWebView正在访问的URL

UIWebView所属的视图的控制器代码中实现委托

@interface tController : UIViewController

 <UIWebViewDelegate>{…}

打开Interface Builder中对应视图,将UIWebView关联到FileOwnerdelegate.

然后直接在tController.m文件中实现方法(不用在头文件中另外声明)

- (BOOL)webView:(UIWebView *)webView

shouldStartLoadWithRequest:(NSURLRequest *)request

        navigationType:(UIWebViewNavigationType)navigationType{

NSURL *url = [request URL];

if (不允许浏览器继续访问该地址){

   return NO;}

else{

return YES;}

}


4、加载本地网页

URLString = [[[NSBundle mainBundle]bundlePath]stringByAppendingPathComponent:@"test.html"];
    NSURL* url = [NSURL fileURLWithPath:URLString];

uiWebView loadUrl………………

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值