跟着教程做一个在线的鲜花浏览App,效果如下:
viewercontroll.h
#import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (strong, nonatomic) IBOutlet UISegmentedControl *colorChoice; @property (strong, nonatomic) IBOutlet UIWebView *flowerView; @property (strong, nonatomic) IBOutlet UIWebView *flowerDetailView; - (IBAction)toggleFlowerDetail:(id)sender; - (IBAction)getFlower:(id)sender; @end
viewercontroll.m
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { self.flowerDetailView.hidden = YES; [self getFlower:nil]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)viewDidUnload { [self setColorChoice:nil]; [self setFlowerView:nil]; [self setFlowerDetailView:nil]; [super viewDidUnload]; } - (IBAction)toggleFlowerDetail:(id)sender { self.flowerDetailView.hidden = ![sender isOn]; } - (IBAction)getFlower:(id)sender { NSURL *imageURL; NSURL *detailURL; NSString *imageURLString; NSString *detailURLString; NSString *color; int sessionID; color = [self.colorChoice titleForSegmentAtIndex:self.colorChoice.selectedSegmentIndex]; sessionID = random()%50000; imageURLString = [[NSString alloc] initWithFormat:@"http://www.floraphotographs.com/showrandomios.php?color=%@&session=%d", color, sessionID]; detailURLString = [[NSString alloc] initWithFormat:@"http://www.floraphotographs.com/detailios.php?session=%d", sessionID]; imageURL = [[NSURL alloc] initWithString:imageURLString]; detailURL = [[NSURL alloc]initWithString:detailURLString]; [self.flowerView loadRequest:[NSURLRequest requestWithURL:imageURL]]; [self.flowerDetailView loadRequest:[NSURLRequest requestWithURL:detailURL]]; self.flowerDetailView.backgroundColor = [UIColor clearColor]; } @end
发现ios原来访问web也是如此easy。。。