1.实现开关方法:
- (IBAction)toggleFlower:(id)sender {
self.flowerDetailView.hidden=![sender isOn];
}
2.实现分段控件和web视图的关联.getFlower方法
- (IBAction)getFlower:(id)sender {
1 //声明发出请求的变量
NSURL *imageURL;
NSURL *detailURL;
NSString *imageURLString;
NSString *detailURLString;
NSString *color;
int sessionID;
2 //获取分段控件实例的标题
color=[self.colorChoice titleForSegmentAtIndex:
self.colorChoice.selectedSegmentIndex];
sessionID=random()%50000;
3//让 imageURLString detailURLString 包含我们讲请求的URl
imageURLString=[NSString stringWithFormat:
@"http://www.floraphotographs.com/showrandomios.php?color=%@&session=%d"
,color,sessionID];
detailURLString=[NSString stringWithFormat:
@"http://www.floraphotographs.com/detailios.php?session=%d"
,sessionID];
4 //使用类方法 URLWithString 创建NSURL对象
imageURL=[NSURL URLWithString:imageURLString];
detailURL=[NSURL URLWithString:detailURLString];
5//loadRequest 加载 :不能处理NSURL对象,只能处理NSURLRequest
[self.flowerView loadRequest:[NSURLRequest requestWithURL:imageURL]];
[self.flowerDetailView loadRequest:[NSURLRequest requestWithURL:detailURL]];
修复程序加载的页面问题:程序加载时,需要隐藏detail
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.flowerDetailView.hidden=YES;
[self getFlower:nil];
}
让theScroller滚动的代码:280和1000分别为theScroller的宽和高- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.theScroller.contentSize=CGSizeMake(280.0,1000.0);
}