开发者

Set UIWebView Address String

开发者 https://www.devze.com 2023-04-02 14:59 出处:网络
Declared Function - (IBAction) changeProductWeb:(NSString *)str; - (IBAction) changeProductWeb:(NSString *)str{

Declared Function

- (IBAction) changeProductWeb:(NSString *)str;


- (IBAction) changeProductWeb:(NSString *)str{

    NSString *urlAddress = str;
    NSURLRequest *request =[NSURLRequest requestWithURL:urlAddress];


    [webView loadRequest:request];

}

Set string using Array

[cell changeProductWeb:[webTitle objectAtIndex:indexPath.row]];

The Array

webTitle = [[NSAr开发者_运维技巧ray alloc] initWithObjects:

            @"bar.html",
            @"bar.html",
            @"bar.html",
            @"bar.html",

            nil];

When I launches it chrashes, if I set the string staticaly in the:

- (IBAction) changeProductWeb:(NSString *)str{

It works fine


[NSURLRequest requestWithURL:] wants an NSURL, not an NSString. Try something like this instead:

    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:urlAddress]];


I am not sure how it works fine setting it statically because you are passing the incorrect type to NSURLRequest. requestWithURL: requires an NSURL not an NSString.

NSURL *urlAddress = [NSURL URLWithString:str];
NSURLRequest *request =[NSURLRequest requestWithURL:urlAddress];
0

精彩评论

暂无评论...
验证码 换一张
取 消