2013年8月22日星期四

UI控件---UIWebView - 小木头_迪

本邮件内容由第三方提供,如果您不想继续收到该邮件,可 点此退订
UI控件---UIWebView - 小木头_迪  阅读原文»

UIWebView是内置浏览器控件,可以用来浏览网页,文档等,今天就试着做一个简易的浏览器!

定义url的初始化方法和返回,前进,刷新三个方法,实现UIWebViewDelegate协议

@interface WebViewController : BaseViewController<UIWebViewDelegate>{

NSString
*_url;
}

-(id)initWithUrl:(NSString*)url; //创建viewController的时候初始化url
- (IBAction)goBack:(id)sender; //返回
- (IBAction)goForward:(id)sender; //前进

- (IBAction)reload:(id)sender; //刷新
@property (retain, nonatomic) IBOutlet UIWebView *webView;

@end

UIWebView的loadRequest方法可以加载一个url地址,需要把url地址变成NSURLRequest参数

- (void)viewDidLoad
{
[super viewDidLoad];

NSURL
*url = [NSURL URLWithString:_url];
NSURLRequest
*request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];

self.title
= @"正在加载";

.networkActivityIndicatorVisible
= YES; //风火轮

}

3个方法的实现

- (IBAction)goBack:(id)sender{

if ([_webView canGoBack]) {
[_webView goBack];
}
}
- (IBAction)goForward:(id)sender{

if ([_webView canGoForward]) {
[_webView goForward];
}

}

- (IBAction)reload:(id)sender{

[_webView reload];
}

实现协议方法,加载成功和加载失败后调用的方法

#pragma mark - WebView Delegate
- (void)webViewDidFinishLoad:(UIWebView *)webView{

.networkActivityIndicatorVisible
= NO; //关闭风火轮
NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];//解析JS代码
self.title = title;

}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{

UIAlertView
*alterview = [[UIAlertView alloc] initWithTitle:@"" message:[error localizedDescription] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alterview show];
[alterview release];
}

总结:了解了webView所需要的参数,加载过程,以及需要实现的协议方法


本文链接:http://www.cnblogs.com/iOS-dd/p/3277205.html,转载请注明。

Python学习之---冒泡,选择,插入排序 - thinkgeek  阅读原文»

最近学习了python基础,写一下3大排序练练手:

1 '''
2 Created on 2013-8-23
3
4 @author: codegeek
5 '''
6
7 def bubble_sort(seq):
8 for i in range(len(seq)):
9 for j in range(i,len(seq)):
10 if seq[j] < seq:
11 tmp = seq[j]
12 seq[j] = seq
13 seq = tmp
14
15 def selection_sort(seq):
16 for i in range(len(seq)):
17 position = i
18 for j in range(i,len(seq)):
19 if seq[position] > seq[j]:
20 position = j
21 if position != i:
22 tmp = seq[position]
23 seq[position] = seq
24 seq = tmp
25
26 def insertion_sort(seq):
27 if len(seq) > 1:
28 for i in range(1,len(seq)):
29 while i > 0 and seq < seq:
30 tmp = seq
31 seq = seq
32 seq = tmp
33 i = i - 1
34
35 if __name__ == "__main__":
36 print "--------bubble_sort-------------"
37 seq = [22,1,33,4,7,6,8,9,11]
38 bubble_sort(seq)
39 print seq
40 print "--------selection_sort-------------"
41 seq = [88,44,33,4,7,6,8,9,11]
42 selection_sort(seq)
43 print seq
44 print "--------insertion_sort-------------"
45 seq = [777,44,33,4,7,6,1111,100,11]
46 insertion_sort(seq)
47 print seq
48


本文链接:http://www.cnblogs.com/thinkgeek/p/3277159.html,转载请注明。

阅读更多内容

没有评论:

发表评论