What rmaddy is saying is that what you wrote as your explanation and what the code shows are not the same. I understand you say you have two view controllers, but you only show the code for one. You are essentially creating one view that sits directly on top of another and has the same dimensions. You will never see the web view underneath this way. If you do something like this you should see both webviews, one on top of the other. That will show you that there really is two there, but one was just hidden behind the other:
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) IBOutlet UIWebView *webView2;
@end
@implementation ViewController
@synthesize scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
draw1 = 0;
scrollView.frame = CGRectMake(0, 300, 480, 55);
[scrollView setContentSize:CGSizeMake(480, 55)];
openMenu.frame = CGRectMake(220, 270, 60, 30);
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height/2)];
NSString *url=@"http://test.bithumor.co/test26.php";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
webview.scrollView.bounces = NO;
[self.view addSubview:webview];
[self.view bringSubviewToFront:webview];
[self.view bringSubviewToFront: openMenu];
[self.view bringSubviewToFront: scrollView];
// Do any additional setup after loading the view, typically from a nib.
UIWebView *webview2=[[UIWebView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height/2, self.view.frame.size.width,self.view.frame.size.height/2)];
NSString *url2=@"http://google.com";
NSURL *nsurl2=[NSURL URLWithString:url2];
NSURLRequest *nsrequest2=[NSURLRequest requestWithURL:nsurl2];
[webview2 loadRequest:nsrequest2];
webview2.scrollView.bounces = NO;
[self.view addSubview:webview2];
[self.view bringSubviewToFront:webview2];
[self.view bringSubviewToFront: openMenu];
[self.view bringSubviewToFront: scrollView];
Edit 1:
If you really want two different view controllers, you need to do something like this:
File 1:
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController
@synthesize scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
draw1 = 0;
scrollView.frame = CGRectMake(0, 300, 480, 55);
[scrollView setContentSize:CGSizeMake(480, 55)];
openMenu.frame = CGRectMake(220, 270, 60, 30);
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
NSString *url=@"http://test.bithumor.co/test26.php";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
webview.scrollView.bounces = NO;
[self.view addSubview:webview];
[self.view bringSubviewToFront:webview];
[self.view bringSubviewToFront: openMenu];
[self.view bringSubviewToFront: scrollView];
File 2:
#import "ViewController2.h"
@interface ViewController2 ()
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController2
@synthesize scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
draw1 = 0;
scrollView.frame = CGRectMake(0, 300, 480, 55);
[scrollView setContentSize:CGSizeMake(480, 55)];
openMenu.frame = CGRectMake(220, 270, 60, 30);
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
NSString *url=@"http://www.google.com";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
webview.scrollView.bounces = NO;
[self.view addSubview:webview];
[self.view bringSubviewToFront:webview];
[self.view bringSubviewToFront: openMenu];
[self.view bringSubviewToFront: scrollView];
If you are using storyboards or nibs, then you would want to set each view controller to a different class. One will get set to ViewController, the other to ViewController2
Edit 2:
To do this in one file you could do something like this:
ViewController.h:
...
@interface ViewController : UIViewController
@property (strong, nonatomic) NSString *urlString;
@end
ViewController.m:
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController
@synthesize scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
draw1 = 0;
scrollView.frame = CGRectMake(0, 300, 480, 55);
[scrollView setContentSize:CGSizeMake(480, 55)];
openMenu.frame = CGRectMake(220, 270, 60, 30);
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
NSURL *nsurl=[NSURL URLWithString:self.urlString];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
webview.scrollView.bounces = NO;
[self.view addSubview:webview];
[self.view bringSubviewToFront:webview];
[self.view bringSubviewToFront: openMenu];
[self.view bringSubviewToFront: scrollView];
File where you present your web view controller:
...
ViewController *webViewController = [[ViewController alloc] init];
webViewController.urlString = @"http://www.google.com";
[self presentViewController:webViewController animated:YES completion:nil];
Or if it's presented via segue you can do set the urlString property in the prepareForSegue method
...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"yourSegueIDHere"]) {
ViewController *webViewController = (ViewController *)segue.destinationViewController;
webViewController.urlString = @"http://www.google.com";
}
}
...
viewDidLoad
method creates and add BOTH web views and add them both to this ONE view controller. – rmaddy