我一直在为 iOS 编写一个 Web 浏览器应用程序并偶然发现了一个问题。起初我的搜索文本字段和网络视图在同一个视图中(一切都很好:)。当我将 web 视图放在不同的视图中时,web 视图不会加载页面并保持空白。所以问题是 web 视图不会加载到不同的视图中(如果文本字段和 web 视图在同一个视图中,则可以工作)。
我的代码:
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
@end
@implementation ViewController
@synthesize searchButton;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib
}
-(IBAction)SearchButton:(id)sender {
NSString *query = [searchField.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com/search?q=%@", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
ViewController *WebView = [self.storyboard instantiateViewControllerWithIdentifier:@"WebView"];
[self presentViewController:WebView animated:YES completion:nil];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end