Webview not working in c lens

I am trying to load a series of URLs based on the contents of my database, i.e. http://www.whatever.com , but when I run the application in the simulator nothing appears, my code reads as follows

.h file (import exception exception)

@interface FSFourthScreenViewController : UIViewController

//insert code to create web view
{
    NSString * urlString;
    UIWebView * FSWebView;
}

// properties
@property (nonatomic, retain) NSString * urlString;
@property (nonatomic, retain) IBOutlet UIWebView * FSWebView;

@end

.x file import exceptions.

@interface FSFourthScreenViewController ()

@end

@implementation FSFourthScreenViewController

@synthesize FSWebView, urlString;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    //background image
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgroundimage.png"]];

    NSURL * url = [NSURL URLWithString:urlString];
    NSURLRequest * requestObj = [NSURLRequest requestWithURL:url];
    [FSWebView loadRequest:requestObj];

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

I connected the webview correctly and assigned the correct field in the database. I also cleared xcode and the simulator, but still no joy ... any ideas are welcome?

+4
source share
8 answers

add this code, check your objects:

  - (void)viewDidLoad
    {
        [super viewDidLoad];

        //background image
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgroundimage.png"]];

        NSURL * url = [NSURL URLWithString:urlString];

        if (!url)
        {
            NSLog(@"url is nil!!!");
        }


        NSURLRequest * requestObj = [NSURLRequest requestWithURL:url];

        if (!FSWebView)
        {
            NSLog(@"RSWebView is nil!!!");
        }

        [FSWebView loadRequest:requestObj];

    }

I think the url is null or the webview is null

+1

,

[self.FSWebView loadRequest:requestObj];
0

urlString. , , urlString , URL, , .

0

, UIWebViewDelegate FSFourthScreenViewController.h. WebView FSFourthScreenViewController.m

UIWebViewDelegate:

Documentation

0

. urlString NULL. . URL-,

0

<UIWebViewDelegate>

self.FSWebView.delegate=self;
 NSURL* url = [NSURL URLWithString:@"http://i.wrightscs.com"]; //replace your string here
  [self.FSWebView loadRequest:[NSURLRequest requestWithURL:url]];

, ...

-1

Source: https://habr.com/ru/post/1528944/


All Articles