我试图通过调用主视图控制器来调用UIWebViews
在其他视图中声明的两个。ScrollView 正在显示,但问题是未加载到滚动视图。我的代码有什么问题?(AppleViewController & GoogleViewController)
UIScrollView
UIWebView
ViewController.h文件
- (void)viewDidLoad
{
[super viewDidLoad];
self.scrollView = [[[UIScrollView alloc] init] autorelease];
self.scrollView.delegate = self;
[self.view addSubview:self.scrollView];
CGSize scrollViewContentSize = CGSizeMake(640, 404);
[self.scrollView setContentSize:scrollViewContentSize];
[self.scrollView setPagingEnabled:YES];
self.scrollView.showsHorizontalScrollIndicator = YES;
pageControl = [[[UIPageControl alloc] init] autorelease];
pageControl.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
pageControl.numberOfPages = 3;
pageControl.currentPage = 0;
[self.view addSubview:pageControl];
pageControl.backgroundColor = [UIColor blueColor];
AppleViewController *apple=[[AppleViewController alloc]init];
GoogleViewController *google=[[GoogleViewController alloc]init];
[self.scrollView addSubview:apple.view];
[self.scrollView addSubview:google.view];
[scrollView setPagingEnabled:YES];
}
AppleViewController.h
- (void)viewDidLoad
{
[super viewDidLoad];
webview2=[[UIWebView alloc]initWithFrame:CGRectMake(10, 500,750,350)];
[webview2 setBackgroundColor:[UIColor redColor]];
NSString *url2=@"http://www.apple.com";
NSURL *nsurl2=[NSURL URLWithString:url2];
NSURLRequest *nsrequest2=[NSURLRequest requestWithURL:nsurl2];
[webview2 loadRequest:nsrequest2];
[self.view addSubview:webview2];
[webview2 setScalesPageToFit:NO];
webview2.multipleTouchEnabled=YES;
[[webview2 layer] setCornerRadius:10];
[webview2 setClipsToBounds:YES];
[[webview2 layer] setBorderColor:
[[UIColor blackColor] CGColor]];
[[webview2 layer] setBorderWidth:2.75];
[[self view] addSubview:webview2];
[webview2 release];
}
////GoogleViewController.h
- (void)viewDidLoad
{
[super viewDidLoad];
webview=[[UIWebView alloc]initWithFrame:CGRectMake(10, 0,750,350)];
[[webview layer] setCornerRadius:10];
[webview setClipsToBounds:YES];
[[webview layer] setBorderColor:
[[UIColor blackColor] CGColor]];
[[webview layer] setBorderWidth:3];
[[self view] addSubview:webview];
[webview release];
NSString *url=@"http://www.google.com";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
[self.view addSubview:webview];
[webview setScalesPageToFit:YES];
webview.multipleTouchEnabled=YES;
[webview goBack];
[webview goForward];
webview.opaque = YES;
webview.backgroundColor = [UIColor clearColor];
}