【代码笔记】点击搜索跳转到另外一个页面
2016-01-14 09:17
513 查看
一,效果图。
二,工程图。
三,代码。
RootViewController.h
RootViewController.m
DetailViewController.h
DetailViewController.m
二,工程图。
三,代码。
RootViewController.h
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end
RootViewController.m
#import "RootViewController.h" #import "DetailViewController.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //初始化搜索框 [self creatSearchBar]; } #pragma -mark -functions -(void)creatSearchBar { UIImageView * searchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search"]]; searchView.frame = CGRectMake(0, 80, 320, 40); searchView.userInteractionEnabled = YES; [self.view addSubview:searchView]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] init]; tap.numberOfTouchesRequired = 1; [tap addTarget:self action:@selector(searchViewPress:)]; [searchView addGestureRecognizer:tap]; UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 20)]; titleLabel.text = @"搜索"; titleLabel.font = [UIFont systemFontOfSize:12]; [searchView addSubview:titleLabel]; } #pragma -mark -doClickActions -(void)searchViewPress:(UIGestureRecognizer *)tap { DetailViewController *detail=[[DetailViewController alloc]init]; [self.navigationController pushViewController:detail animated:NO]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
DetailViewController.h
#import <UIKit/UIKit.h> @interface DetailViewController : UIViewController @end
DetailViewController.m
#import "DetailViewController.h" @interface DetailViewController () @end @implementation DetailViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
相关文章推荐
- java 读写绝对路径的properties文件
- 【代码笔记】点击搜索跳转到另外一个页面
- Python集合
- 谷歌想要返华,但却陷入了尴尬境地
- [原创]解决使用Qt creator时…
- 从 Qt 的 delete 说开来
- [原创]c++整型提升(类型转换)
- 运用VC#编程通过OPC方式实现PC机与西门子PLC通讯《异步篇》
- C语言scanf函数详细解释
- c/c++优先级列表
- C/C++浮点数在内存中的存储…
- C++虚函数表解析
- C++五大内存分区及区别
- 关于Struts2 Action中get和set惹得祸。
- obj-c语言学习-----苹果官网
- Posix多线程编程—线程属性【转】
- 【转载】对缓冲区的理解 C++
- 【转载】C++文件操作详解(ifstrea…
- 运用VC#编程通过OPC方式实现PC机与西门子PLC通讯《异步篇》
- 如何提高Web服务端并发效率的异步编程技术