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

      

  • 相关阅读:
    2018-2019-1 20165231 实验三 实时系统
    2018-2019-1 20165231 《信息安全系统设计基础》第七周学习总结
    2018-2019-1 20165231 《信息安全系统设计基础》第六周学习总结
    2018-2019-1 20165232 20165231 20165235实验二——固件程序设计
    2018-2019-1 20165231《信息安全系统设计基础》第五周学习总结
    2018-2019-1 20165231 20165232 20165235 实验一 开发环境的熟悉
    2018-2019-1 20165231 《信息安全系统设计基础》第四周学习总结
    20165115 2017-2018-2《Java程序设计》课程总结
    结对编程练习_四则运算 第二周总结 20165115
    20165115 实验二《Java面向对象程序设计》实验报告
  • 原文地址:https://www.cnblogs.com/wsq724439564/p/3302805.html
Copyright © 2011-2022 走看看