iOS 用の Web ブラウザー アプリをプログラミングしていて、問題に遭遇しました。最初は、検索テキスト フィールドと 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