iOS按钮到uiwebview的网页 [英] iOS button to webpage with uiwebview
问题描述
对于当前项目,我将移动网站嵌入到iOS应用中。我使用了UIWebView的goback()和goforward()函数。但是我如何创建一个自定义函数onClick(或onTouch哪个是正确的术语)将UIWebView发送回最初加载的页面?任何帮助都会非常感激,因为到目前为止我无法在网上找到任何东西。
添加类似于实现文件的内容:
- (IBAction)loadPage:(id)sender;
{
NSURL * url = [NSURL URLWithString:@http://www.stackoverflow.com/];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
并将其添加到头文件(每行在适当的位置):
- (IBAction)loadPage:(id)sender;
IBOutlet UIWebView * webView;
然后将按钮绑定到界面构建器中的loadPage,
并将webView绑定到UIWebView。
回复评论:
我创建了这个示例项目,希望它有所帮助:
- http://dd5.org/static/iPhone_Browser_Sample.zip
绑定按钮:
右键单击并拖动到添加了上面的代码。
释放按钮。现在应该出现一个暗灰色的小面板。
然后单击该面板中的loadPage:条目。
如果代码添加正确,则该条目应该显示在那里。 / p>
For a current project I am embedding a mobile site into an iOS app. I've taken use of the goback() and goforward() functions, with UIWebView. But how would I make a custom function that onClick (or onTouch which ever is the correct term) Sends the UIWebView back to the page initially loaded? Any Help would be much appreciated as I have bene unable to find anything on the web thus far.
Add something like to the implementation file:
- (IBAction)loadPage:(id)sender;
{
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
And add this to the header file (each line at the appropriate position):
- (IBAction)loadPage:(id)sender;
IBOutlet UIWebView *webView;
Then bind the button to loadPage within interface builder,
and bind webView to the UIWebView.
Response to comment:
I created this sample project, hopefully it helps:
- http://dd5.org/static/iPhone_Browser_Sample.zip
Binding the button:
Right-click and drag to the class where you added the code above.
Release the button. Now a little dark-gray panel should appear.
Then click on the loadPage: entry within that panel.
If the code was added correctly, the entry should show up there.
这篇关于iOS按钮到uiwebview的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!