Set UIWebView Address String
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];
精彩评论