Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to load url, what come from popoverclass?
    text
    copied!<p>This is probably is pretty easy, but I'm stuck with it today. The idea is that in my browser, I've create uiwebview and I want to implimate address bar in popover with it own class. I can get the url from UItextfield from popover class to webview class, but when I get it uiwebview get lazy and it doesn't load it. When I check it, debuger says that webview is null. This is ViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "AdressBar.h" #import "mypopoverController.h" @interface ViewController : UIViewController&lt;AddressbarDelegate&gt; { UIWebView* mWebView; mypopoverController *popoverController; } @property (nonatomic, retain) IBOutlet UIWebView* webPage; @end </code></pre> <p>This is ViewController.m:</p> <pre><code> #import "mypopoverController.h" #import "MyOwnPopover.h" #import "ViewController.h" #import "AdressBar.h" @interface ViewController () @end @implementation ViewController @synthesize webPage = mWebView; - (void)viewDidLoad { [super viewDidLoad]; addressBar = [[AdressBar alloc] init]; addressBar.delegate = self; [edittext addTarget:self action:@selector(showPopoverAdressBar:forEvent:) forControlEvents:UIControlEventTouchUpInside]; NSURL *url = [NSURL URLWithString:@"http://www.google.lv"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [mWebView setScalesPageToFit:YES]; [mWebView setDelegate:self]; [mWebView loadRequest:request]; } -(void)loadReceivedAddress:(NSURLRequest *)url{ NSLog(@"url= %@", url);//there url always is not null and mWebView should load it if(mWebView != nil){ [mWebView loadRequest:url]; }else{ NSLog(@"mWebView is null");//...but there it say's that it's null }} -(void)showPopoverAdressBar:(id)sender forEvent:(UIEvent*)event { AdressBar *popoverControllesr = [[AdressBar alloc]init]; popoverControllesr.view.frame = CGRectMake(0,0, 600, 45); popoverControllesr.view.backgroundColor = [UIColor whiteColor]; popoverController = [[mypopoverController alloc] initWithContentViewController:popoverControllesr]; popoverController.cornerRadius = 20; if(_titles!=NULL){ popoverController.titleText = _titles;}else{ popoverController.titleText = @"Loading..."; } popoverControllesr.address.text = absoluteString; popoverController.popoverBaseColor = [UIColor orangeColor]; popoverController.popoverGradient= YES; popoverController.arrowPosition = TSPopoverArrowPositionHorizontal; [popoverController showPopoverWithTouch:event]; } @end </code></pre> <p>This is AdressBar.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @protocol AddressbarDelegate &lt;NSObject&gt; @required -(void)loadSomethingFromAddressBar:(NSURLRequest*)request; @end @interface AdressBar : UIViewController{ IBOutlet UIButton *cancel; } @property (nonatomic, retain) IBOutlet UITextField *address; @property (nonatomic, retain) NSURLRequest *request; @property(nonatomic, weak) id &lt;AddressbarDelegate&gt; delegate; @end </code></pre> <p>This is AdressBar.m:</p> <pre><code>#import "AdressBar.h" #import "ViewController.h" @interface AdressBar () @end @implementation AdressBar @synthesize delegate = delegate; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. [_address setDelegate:self]; _address.clearButtonMode = UITextFieldViewModeWhileEditing; _address.keyboardType = UIKeyboardTypeURL; [_address addTarget:self action:@selector(loadAddresss) forControlEvents:UIControlEventEditingDidEndOnExit]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)loadAddresss { NSString* urlString = _address.text; NSURL* url = [NSURL URLWithString:urlString]; if(!url.scheme) { NSString* modifiedURLString = [NSString stringWithFormat:@"http://%@", urlString]; url = [NSURL URLWithString:modifiedURLString]; } NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSLog(@"request= %@", request); NSLog(@"text= %@", urlString); if (request!=nil) { if(delegate!=nil) {NSLog(@"delegate not nil"); [delegate loadSomethingFromAddressBar:request]; }else{ NSLog(@"delegate is nil");//There delegate always is nil } } } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload