我是 Objective C 编程和 cocoa 应用程序的新手。
这是我的基于 static URL
webview 的应用程序。
AppDelegate.h 包含
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet WebView *webview;
@end
我的 AppDelegate.m 包含
@implementation AppDelegate
@synthesize webview;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *urlString = @"http://www.google.com";
[[webview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}
@end
使用此指定的 URL
可以正常工作。
我正在尝试找到使我能够配置 URL 的解决方案。 例如,从单独的窗口保存 URL,并通过点击“保存”按钮加载带有新指定 URL 的 Web View 。
提前致谢
最佳答案
创建一个UITextField
和一个UIButton
。单击按钮后,加载插入到文本字段中的 URL。
例如,假设您的文本字段名为 _tf,您的 Web View 名为 _wv:
- (IBAction)btnClicked
{
[_wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_tf.text]]];
}
当然,您需要验证输入的文本实际上是有效的 URL。
关于objective-c - 具有可配置 URL 的 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15759239/