English 中文(简体)
UI WebView - 装入在驳回时留下的 URLView
原标题:UIwebView - load the URL it was left with upon dismissView

我有以下代码 允许我每次加载一个固定的 URL, 放在我的视野 是否Load 方法 :

NSString *urlAddress =  @"http://google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];

现在用户当然可以从这里进入任何网页, 如果用户决定删除我所希望的视图, 让他们能回到网页上。

现在我有了这个代码, 通过阅读各种论坛和搜索:

景象又变了,现在看起来是这样的:

NSURLRequest *currentRequest = [_webView request];
NSURL *currentURL = [currentRequest URL];

if(currentURL != nil) 
{
NSString *urlAddress = currentRequest;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
}
else {
NSString *urlAddress =  @"http://google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
}

依我看来,我曾有这样的东西:

-(void)viewDidUnload {

NSURLRequest *currentRequest = [_webView request];
NSURL *currentURL = [currentRequest URL];
NSLog(@"Current URL is %@", currentURL.absoluteString);


[NSURLConnection connectionWithRequest:currentRequest delegate:self];

}

(a) 我是否走上了实现这一目标的正确轨道?

b) I have a warning created on this line : `` `NSString *urlAddress = currentRequest; which is:

不兼容的指针类型 初始化NSString ++++ 表示型号 NSURL 请求 +% 强

感谢任何帮助:-)

谢谢:-)

"https://stackoverflow.com/ questions/10711027/stop-uiwebview- from-loading-the-set-url-每次- when-it-gets-loaded"我开始在这个问题上提出这个问题,但觉得这个问题值得新问题,如果你不这么想,请原谅我。

`` `

最佳回答
NSString *urlAddress = currentRequest;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];

可能只是

[_webView loadRequest:currentRequest];

当用户将视图/视图控制器卸下时, 您可能想要尝试不卸载视图/ 视图控制器, 然后当用户把它带回来时就不会有延迟 。 (也许您可以把它隐藏起来, 而不是卸下它, 比如当用户将其卸下时, 或者发送到导航控制器堆放的后面, 假设您有一个作为根视图控制器的话 ) 。

P.S. Your warning is because you re trying to assign an NSURLRequest object to an NSString object.

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签