利用SegmentedControl切换控制器的view
#import "ViewController.h"
#import "OneViewController.h"
#import "TwoViewController.h"
@interface ViewController ()
@property (nonatomic, strong) UISegmentedControl *segmentedControl;
@property (nonatomic, strong) UIViewController *currentViewController;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"第一个视图",@"第二视图"]];
self.segmentedControl.frame = CGRectMake(0, 0, 150, 30);
self.navigationItem.titleView = self.segmentedControl;
[self.segmentedControl addTarget:self action:@selector(segmentedControl:) forControlEvents:UIControlEventValueChanged];
_segmentedControl.selectedSegmentIndex = 0;
OneViewController *oneVC = [[OneViewController alloc] init];
[self addChildViewController:oneVC];
TwoViewController *twoVC = [[TwoViewController alloc] init];
[self addChildViewController:twoVC];
[self setSelectController:0];
}
- (void)segmentedControl:(UISegmentedControl*)scc{
[self setSelectController:scc.selectedSegmentIndex];
}
- (void)setSelectController:(NSInteger)index{
UIViewController *vc = [self.childViewControllers objectAtIndex:index];
if (vc == self.currentViewController) {
return;
}
[self.currentViewController.view removeFromSuperview];
vc.view.frame = CGRectMake(0, 0, 320, 200);
[self.view addSubview:vc.view];
_currentViewController = vc;
}
利用SegmentedControl切换控制器的view的更多相关文章
- iOS利用Runtime自定义控制器POP手势动画
前言 苹果在iOS 7以后给导航控制器增加了一个Pop的手势,只要手指在屏幕边缘滑动,当前的控制器的视图就会跟随你的手指移动,当用户松手后,系统会判断手指拖动出来的大小来决定是否要执行控制器的Pop操 ...
- iOS开发——UI进阶篇(八)pickerView简单使用,通过storyboard加载控制器,注册界面,通过xib创建控制器,控制器的view创建,导航控制器的基本使用
一.pickerView简单使用 1.UIPickerViewDataSource 这两个方法必须实现 // 返回有多少列 - (NSInteger)numberOfComponentsInPicke ...
- 使用容器控制器控制另外两个控制器的view交换
建三个UIViewController 的子控制器,其中一个为根控制器,另外两个控制器的视图作为切换对象 AppDelegate中代码 //AppDelegate.h中代码 #import <U ...
- iOS 容器控制器 (Container View Controller)
iOS 容器控制器 (Container View Controller) 一个控制器包含其他一个或多个控制器,前者为容器控制器 (Container View Controller),后者为子控制器 ...
- iOS架构师之路:控制器(View Controller)瘦身设计
前言 古老的MVC架构是容易被iOS开发者理解和接受的设计模式,但是由于iOS开发的项目功能越来越负责庞大,项目代码也随之不断壮大,MVC的模糊定义导致我们的业务开发工程师很容易把大量的代码写到视图控 ...
- iOS开发——UI进阶篇(十)导航控制器、微博详情页、控制器的View的生命周期
一.导航控制器出栈 1.initWithRootViewController本质 UIViewController *vc = [[OneViewController alloc] init]; // ...
- iOS开发UI篇—控制器的View的创建
iOS开发UI篇—控制器的View的创建 一.6种创建控制器View的方式 #import "NJAppDelegate.h" #import "NJViewContro ...
- 自定义控制器的View(loadView)及其注意点
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- 【转】 iOS开发UI篇—控制器的View的创建
最近对view的周期等还不是非常清楚,就找到顶哥的文章,非常不错,就搬运过来了. 原文: http://www.cnblogs.com/wendingding/p/3770760.html 一.6种创 ...
随机推荐
- Linux下配置IP及安装vmware tool
=======================CentOS 7以下======================= 配置IP: 1.获得mac地址 2.编辑ifcfg-eth0文件:vi /etc/sy ...
- List接口、Set接口、Map接口的方法
一.Collection接口中的方法介绍 int size();返回此Collection中的元素数 boolean isEmpty(); 判断是否为空 boolean containsAll(Col ...
- parseInt方法——将字符串解析为int值
parseXxx()方法 语法:static int parseInt(String s) 返回字符串的十进制整数形式 static int parseInt(String s, int rad ...
- Bootstrap网格系统
一.网格系统 响应式网格系统随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. 二.基本结构 <div class="container"> &l ...
- merge,join,concat
merge交集 join并集 concat axis=0 竖着连 axis=1 横着连
- MySql学习(四) —— 函数、视图
注:该MySql系列博客仅为个人学习笔记. 本篇博客主要涉及MySql 函数(数学函数.字符串函数.日期时间函数.流程控制函数等),视图. 一.函数 1. 数学函数 对于数学函数,若发生错误,所有数学 ...
- PDF 补丁丁 0.5.0.2657 发布
新版本修正了导出图片时由于路径存在空白导致出错.在 Windows 10 和高分辨率显示屏上显示字体模糊.控件尺寸错位等各种问题. 默认显示工具栏.
- Struts2 Result 类型和对应的用法详解
- algorithm -- 插入排序
插入排序是<算法导论>中第一个介绍的算法,详细分析了插入排序的原理,执行过程,证明了算法的正确性.同时也引出了算法分析和算法分析常用的方法. 此文对原文作个转述,检验学到的知识. 文中使用 ...
- Spring.NET 与 AOP 初窥1
(方面:如有错误,请勿喷,评论即可) 1.开始 什么是AOP?关于它的详细内容,可以自己用google搜索一下,能找到很多有趣的内容.事实上,现在的AOP只是对OOP的一个补充,还没有到达一个语言级别 ...