ios 随笔_基于uiwebview的浏览器开发
好http://xinsheng.huawei.com/cn/index.php?app=forum&mod=Detail&act=index&id=991831
1.const char * ->NSString : [NSString stringWithCString:(const char*) encoding:NSUTF8StringEncoding];
2.多窗口浏览 可以使用WEpopover 实现;
3.浏览器设置的弹窗使用WEpopover 调用自定义的Cell 类实现,然后使用delegate来完成各个按钮的相关操作(注意对delegate的赋值);http://blog.csdn.net/soloterry/article/details/7633235
4.子View 调用父View的方法或者变量 使用delegate;
5.UITableVeiw cell行数动态变化可以使用NSMutableArry 实现
6.NSError [error code]不想显示的直接if(){return}掉 [error code 101]不小心把url 加载了两次:“The url cant be shown”
7.[(UIButton *)button adjustsImageWhenDisabled]选择后取消高亮???
8.UIWebView本身是支持在线浏览的,通过
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ if (navigationType == UIWebViewNavigationTypeLinkClicked) { return NO; } return YES; }
对该功能进行控制
9.uiwebview 与JS的交互:http://blog.csdn.net/xdonx/article/details/6973521
10.得到request网页的filename :
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ if (navigationType == UIWebViewNavigationTypeLinkClicked) { NSHTTPURLResponse *response; [NSURLConnection sendSynchronousRequest:request returningResponse:@response error:nil]; //得到html head 头 NSDictionary *dictionary = [resopnse allHeadFields]; NSLog(@"%@",[dictionary description]); NSString *fileName; NSString *exFileName; //得到filename和后缀名 filename = [response suggestedFilename]; exFileName = [fileName pathExtension]; return NO; } return YES; }
11.UI控件罗控件,如何使底层控件显示???????(done )
{ 仅对于UITextfield 而言 只需把 [UITextfield setBackGroundColor:[UIColor clearColor]]}
12.UIProgressBar 的自定义显示以及根据得到网页数据大小的加载过程?????(done)
{
使用图片代替UIPressBar,通过根据所请求连接返回数据包(调用NSURLConnectionDelegate的方法)的大小对图片的CGRect的宽度进行调节,达到进度条的效果。
- (BOOL)webView:(UIWebView *)webView1 shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSHTTPURLResponse *response; [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil]; //2012.9.21 [NSURLConnection connectionWithRequest:request delegate:self]; //2012.9.21 contentSize = [response expectedContentLength]; NSLog(@"contentSize0:%f",contentSize); NSDictionary *dictionary = [response allHeaderFields]; NSLog(@"allHeaderFields:%@",[dictionary description]); NSString *fileName; NSString *exFileName; fileName = [response suggestedFilename]; NSLog(@"%@",fileName); exFileName = [fileName pathExtension]; NSLog(@"%@",exFileName); if (navigationType == UIWebViewNavigationTypeLinkClicked) { if ([exFileName isEqualToString:@"xlsx"] || [exFileName isEqualToString:@"doc"] || [exFileName isEqualToString:@"ppt"] || [exFileName isEqualToString:@"pdf"] ) { UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Sorry" message:@"The File is Forbidded To Open " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; return NO; } return YES; } return YES; } #pragma mark - NSURLConnection Delegate //响应时触发 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { proValue = 0; } //每收到一次数据调用一次 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { double receiveData = [data length]; NSLog(@"receiveDataLength:%f",receiveData); NSLog(@"contentSize1:%f",contentSize); proValue += receiveData/contentSize; NSLog(@"dataProvalue:%f",proValue); if (proValue < 1) { if (proValue < 0.8 ) { timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeProgress) userInfo:nil repeats:YES]; [timer fire]; }else { [self setProgress:proValue]; } } else { timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeProgress) userInfo:nil repeats:YES]; [timer fire]; } } //网络错误时触发 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { } //数据加载完触发 - (void)connectionDidFinishLoading:(NSURLConnection *)connection { proValue = 0.9; [self setProgress:proValue]; } - (void)setProgress:(float)fProgress { CGSize size = textField.frame.size; progressImageView.frame = CGRectMake(0, 0,size.width*fProgress ,31 ); } - (void)changeProgress { proValue += 0.1; if (proValue < 0.9) { [self setProgress:proValue]; }else { [self setProgress:proValue]; [timer invalidate]; } } }
13.如何用代码的方式使得控件一层层的显示?????(done)
{ 控件初始化后 对应一层层的addSubview 而后release 一下 };
14.UIImageView详解:http://www.cnblogs.com/didiaodexi/articles/2422580.html
15.cell 上 addSubview :[cell.contentView addSubview:(UIView *)];(Failed!!!)
(苹果文档中不鼓励我们在UITableViewCell中添加subView,最好采用自定义Cell,将需要的SubView添加到Cell当中。)
好文章《苹果的重用机制》:http://blog.csdn.net/andypan1314/article/details/7192493
17.A包含的B头文件中包含C头文件 故在A类的内部变量可直接调用C类!!!!
浙公网安备 33010602011771号