zoukankan      html  css  js  c++  java
  • Objective-C ,ios,iphone开发基础:3分钟教你做一个iphone手机浏览器

    第一步:新建一个Single View工程:

    第二步:新建好工程,关闭arc。

    第三步:拖放一个Text Field 一个UIButton 和一个 UIWebView . Text Field 的title 属性设置为 http:// 。UIButton 的title属性设置为 go 。 布局如图:

    第四步:为Text Field 和  UIWebView 连线,插座变量分别命名为  textUrl  和 webRequest。为UIButton 连线 .连接一个action事件(- (IBAction)btnGo:(id)sender;)

     

     然后在(- (IBAction)btnGo:(id)sender;里面添加代码:

    - (IBAction)btnGo:(id)sender {
        NSURL* url = [[NSURL alloc] initWithString:textUrl.text];
        NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url];
        [webRequest loadRequest:request];
        [textUrl resignFirstResponder];
        [url release];
        [request release];
    }

    到此。一个简单浏览器设计就完成了 。运行如下:输入 http://sina.com.cn

     整个项目代码如下:

    //
    //  wsqViewController.h
    //  webTest
    //
    //  Created by administrator on 13-9-5.
    //  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface wsqViewController : UIViewController {
        UITextField *textUrl;
        UIWebView *webRequest;
    }
    
    @property (retain, nonatomic) IBOutlet UITextField *textUrl;
    
    @property (retain, nonatomic) IBOutlet UIWebView *webRequest;
    - (IBAction)btnGo:(id)sender;
    @end
    //
    //  wsqViewController.m
    //  webTest
    //
    //  Created by administrator on 13-9-5.
    //  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
    //
    
    #import "wsqViewController.h"
    
    @implementation wsqViewController
    @synthesize textUrl;
    @synthesize webRequest;
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
       
    }
    
    #pragma mark - View lifecycle
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
    }
    
    - (void)viewDidUnload
    {
        [self setTextUrl:nil];
        [self setWebRequest:nil];
        [super viewDidUnload];
        
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    }
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    }
    
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    }
    
    - (void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }
    
    - (void)dealloc {
        [textUrl release];
        [webRequest release];
        [super dealloc];
    }
    - (IBAction)btnGo:(id)sender {
        NSURL* url = [[NSURL alloc] initWithString:textUrl.text];
        NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url];
        [webRequest loadRequest:request];
        [textUrl resignFirstResponder];
        [url release];
        [request release];
    }
    @end

      

  • 相关阅读:
    window在文件管理器中打开命令行窗口
    js的事件机制
    ext-css
    HTML防止input回车提交表单
    myeclipse调试代码的时候看不到变量的值和jdk源码重新编译
    MANIFEST.MF 文件内容完全详解
    Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'dll.msvcrt'
    JNA知识点
    cookie 和session 的区别
    6- js监听输入框值的即时变化onpropertychange、oninput
  • 原文地址:https://www.cnblogs.com/wsq724439564/p/3302805.html
Copyright © 2011-2022 走看看