在 UIWebView 中打开一个 URL

Open an URL in UIWebView

我有一个重要的问题。我正在创建一个 iPhone 应用程序。 我有一个带有 goBack、goForward 和重新加载的 UIWebView (https://www.google.de/)。 现在,我想要一个按钮,例如名为 Home 或 Homepage 的 Bar Button Item,用于在此 WebView 中打开 URL (https://www.google.de/),返回主页。 我怎样才能做到这一点?我怎样才能 "say" 在我的 WebView 中打开 link 按钮?我求解答

//  ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (nonatomic, strong) IBOutlet UIWebView *site   ;
@end



//  ViewController.m

#import "ViewController.h"

@interface ViewController ()
@end
@implementation ViewController
-(IBAction)refresh:(id)sender; {

    NSURL *url=[NSURL URLWithString: @"https://www.google.de/"]; NSURLRequest * requestURL=[NSURLRequest requestWithURL:url]; [_site loadRequest:requestURL];

}
- (void)viewDidLoad {

    [self refresh:self];

    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

}
- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}
@end

UIWebView 有方法,goBackgoForward。您可以进行操作并将其与您的条形按钮绑定,以便随时返回和前进。

- (IBAction)goBack:(id)sender {
    [_site goBack];
}

- (IBAction)goForward:(id)sender {
    [_site goForward];
}

- (IBAction)goHomepage:(id)sender {
    NSURL *url=[NSURL URLWithString: @"https://www.google.de/"]; 
    NSURLRequest *requestURL=[NSURLRequest requestWithURL:url]; 
    [_site loadRequest:requestURL];
}

为了给您更多帮助,here's a tutorial on this, and if you don't want to read that tutorial, you can check their source code from here !