热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ObjectiveC,ios,iphone开发基础:3分钟教你做一个iphone手机浏览器

原文链接:http:www.cnblogs.comwsq724439564p3302805.html第一步:新建一个SingleView工程:第二步:新建好工程,关闭arc。第三步


原文链接:http://www.cnblogs.com/wsq724439564/p/3302805.html

第一步:新建一个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
@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

 

 

  

转载于:https://www.cnblogs.com/wsq724439564/p/3302805.html



推荐阅读
author-avatar
Aaron Chen
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有