我的iphone开发学习笔记(四)使用UIWebView,UISegmentedControl
2011-12-03 18:47
411 查看
今天练习的主要目标:
1。 使用UIwebView的控件,如何加载远程服务器上的数据
2。 使用UISegmentedControl控件,选择不同段的数值
首先看下练习的最终效果
练习具体步骤:
1. 首先创建一个基于view_based_application, 项目名称为FlowerWebViewControl
2. 然后,打开FlowerWebViewControl.h
添加具体的ui控件
IBOutlet UISegmentedControl *colorChoice;
IBOutletUIWebView *flowerView;
IBOutletUIWebView *detailView;
@property(nonatomic,retain)UISegmentedControl *colorChoice;
@property(nonatomic,retain)UIWebView *flowerView;
@property(nonatomic,retain)UIWebView *detailView;
同时增加一个函数声明
-(IBAction)getFlower:(id)sender;
3. 设计界面
4. 实现UI控件、函数和File's Owner的链接
关于连接的小技巧:
a. 连接UI的方法,
选中File's Owner, 按住control, 画出连线到具体的ui控件(只要在.h中声明过的,就会出现在可供选择的ui列表中),注意不要连接错误
b. 连接控件处理处理函数的方法:
选择具体的UI控件,按住Control, 画出连线到File's Owner, 在下拉列表中选择正确的函数名称,这样控件就和具体的处理函数连接上了。
5. 关于具体控件的处理
a. uisegmentedcontrol,
获取具体数值的方法是:
color = [colorChoicetitleForSegmentAtIndex:colorChoice.selectedSegmentIndex];
b. webView加载html页面的具体方法
首先NSURL使用urlString初始化
然后 webView loadRequestWithUrl: nsurl
具体代码如下
这个例子完成了,关键的技术点
1。 ui的声明、界面添加和连接
2。segmentedControll的数值获取
3。 webview的页面加载nsUrl, webView loadRequest:nsUrl
如果需要工程代码的,请留下邮箱地址。
1。 使用UIwebView的控件,如何加载远程服务器上的数据
2。 使用UISegmentedControl控件,选择不同段的数值
首先看下练习的最终效果
练习具体步骤:
1. 首先创建一个基于view_based_application, 项目名称为FlowerWebViewControl
2. 然后,打开FlowerWebViewControl.h
添加具体的ui控件
IBOutlet UISegmentedControl *colorChoice;
IBOutletUIWebView *flowerView;
IBOutletUIWebView *detailView;
@property(nonatomic,retain)UISegmentedControl *colorChoice;
@property(nonatomic,retain)UIWebView *flowerView;
@property(nonatomic,retain)UIWebView *detailView;
同时增加一个函数声明
-(IBAction)getFlower:(id)sender;
3. 设计界面
4. 实现UI控件、函数和File's Owner的链接
关于连接的小技巧:
a. 连接UI的方法,
选中File's Owner, 按住control, 画出连线到具体的ui控件(只要在.h中声明过的,就会出现在可供选择的ui列表中),注意不要连接错误
b. 连接控件处理处理函数的方法:
选择具体的UI控件,按住Control, 画出连线到File's Owner, 在下拉列表中选择正确的函数名称,这样控件就和具体的处理函数连接上了。
5. 关于具体控件的处理
a. uisegmentedcontrol,
获取具体数值的方法是:
color = [colorChoicetitleForSegmentAtIndex:colorChoice.selectedSegmentIndex];
b. webView加载html页面的具体方法
首先NSURL使用urlString初始化
然后 webView loadRequestWithUrl: nsurl
具体代码如下
// // FlowerWebViewControllerViewController.h // FlowerWebViewController // // Created by 旭 陈 on 11-12-3. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import <UIKit/UIKit.h> @interface FlowerWebViewControllerViewController : UIViewController { IBOutlet UISegmentedControl *colorChoice; IBOutlet UIWebView *flowerView; IBOutlet UIWebView *detailView; // IBOutlet UISwitch *mySwitch; //2webView //segmentedControll } @property(nonatomic,retain)UISegmentedControl *colorChoice; @property(nonatomic,retain)UIWebView *flowerView; @property(nonatomic,retain)UIWebView *detailView; //@property(nonatomic,retain)UISwitch *mySwitch; -(IBAction)getFlower:(id)sender; -(IBAction)toggleFlowerDetail:(id)sender; //getFlower //toggleFlowerDetail @end
// // FlowerWebViewControllerViewController.m // FlowerWebViewController // // Created by 旭 陈 on 11-12-3. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "FlowerWebViewControllerViewController.h" @implementation FlowerWebViewControllerViewController //@synthesize mySwitch; @synthesize flowerView; @synthesize detailView; @synthesize colorChoice; /* // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ /* // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } */ /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } -(IBAction)toggleFlowerDetail:(id)sender{ detailView.hidden = ![sender isOn]; } -(IBAction)getFlower:(id)sender{ NSLog(@"getFlower"); NSURL *imageUrl; NSURL *detailUrl; NSString *imageUrlStr; NSString *detailUrlStr; NSString *color; int sessionID; color = [colorChoice titleForSegmentAtIndex:colorChoice.selectedSegmentIndex]; NSLog(@"%@",color); sessionID = random()%10000; imageUrlStr= [[NSString alloc]initWithFormat:@"http://www.floraphotographs.com/showrandomiphone.php?color=%@&session=%d",color,sessionID]; detailUrlStr = [[NSString alloc]initWithFormat:@"http://www.floraphotographs.com/detailiphone.php?session=%d",sessionID]; imageUrl = [[NSURL alloc]initWithString:imageUrlStr]; detailUrl = [[NSURL alloc] initWithString:detailUrlStr]; [flowerView loadRequest:[NSURLRequest requestWithURL:imageUrl]]; [detailView loadRequest:[NSURLRequest requestWithURL:detailUrl]]; detailView.backgroundColor = [UIColor clearColor]; [imageUrlStr release]; [detailUrlStr release]; [imageUrl release]; [detailUrl release]; } @end
这个例子完成了,关键的技术点
1。 ui的声明、界面添加和连接
2。segmentedControll的数值获取
3。 webview的页面加载nsUrl, webView loadRequest:nsUrl
如果需要工程代码的,请留下邮箱地址。
相关文章推荐
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- 我的iphone开发学习笔记(三)使用UISlide, UIImageView及动画
- ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境(转)
- ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境
- ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境
- ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境
- 我的iphone开发学习笔记(六): 使用选项卡栏管理多视图界面
- 我的iphone开发学习笔记(九): 使用NSUserDefaults读写用户默认设置
- ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境
- IOS 学习笔记17 iPhone开发之使用NSUserDefaults存储数据
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- 我的iphone开发学习笔记(七): 使用UITableViewController
- 我的iphone开发学习笔记(二)使用UITextView, UITextField 和UIButton控件
- iPhone开发学习笔记_剪切板的使用
- iphone开发学习,开源之SVWebViewController,UIWebView支持后退、前进、刷新、使用Safari打开
- iPhone开发学习笔记[3/50]-使用工具栏创建简单的多视图应用程序
- iPhone开发学习笔记[4/50]-表视图的使用
- 第58课:使用Java和Scala在IDE中开发DataFrame实战学习笔记
- IPhone 开发笔记第一天——对基础的学习