#import "ViewController.h" @interface ViewController ()<UIScrollViewDelegate> //保包括这个viewdelegat协议 @property (weak, nonatomic) IBOutlet UITextField *search; //这是输入框 @property (weak, nonatomic) IBOutlet UIWebView *viewbrows; // 这个是浏览器界面视图 @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //初始化载入 } - (IBAction)go:(id)sender { NSString *path =self.search.text; //字符串指针指向输入的文本 //[path stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)]//这个应该是转换代码格式 if (![path hasPrefix:@"http://"]) { //表示判断path前缀是否是http:// path=[@"http://" stringByAppendingString:path]; 没有则添加http://在path前面 } NSURL *url =[NSURL URLWithString:path]; //用url指针指向字符串格式的url path NSURLRequest *request =[NSURLRequest requestWithURL:url]; request请求指向url [self.viewbrows loadRequest:request]; 载入请求的url [self.view endEditing:YES]; //当使徒运行完成后键盘会缩回 } - (IBAction)went:(id)sender { [self.viewbrows goForward]; //前进 } - (IBAction)back:(id)sender { [self.viewbrows goBack]; //后退 } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
时间: 2024-10-27 07:26:07