[IOS]Setting Bundle + StoryBoard
用storyboard添加一个导航栏,其中首页有一个switch,与setting联动,还有一个button,使用modal连接另一个viewControl,其上也有一个按钮,按下销毁本viewControl,回到前一页。
实现步骤:
1.创建一个SingleView的项目,勾选上storyboard。
2.向storyboard中添加一个NavigationController,两个ViewController,然后在NavigationController中右击指向第一个ViewController,然后设置为rootViewController,并且将箭头指向NavigationController。
3.将两个ViewController的Class分别设置为DXWViewController和DXWViewController1(两个自己创建的类,继承自ViewController)
4.创建setting文件,并将root.plist保存一个键值对,key改成switch
5.修改DXWViewController(主视图)
DXWViewController.h:
#import <UIKit/UIKit.h>
#import "DXWViewController1.h"
@interface DXWViewController : UIViewController<DXWFlipsideViewControllerDelegate>
- (IBAction)change:(id)sender;
@property (retain, nonatomic) IBOutlet UILabel *label;
@property (retain, nonatomic) IBOutlet UISwitch *switchButton; - (IBAction)showInfo:(id)sender; @end
DXWViewController.m:
#import "DXWViewController.h" @interface DXWViewController () @end @implementation DXWViewController -(void)viewWillAppear:(BOOL)animated
{
[self changeData];
} -(void)changeData
{
NSUserDefaults *usr = [NSUserDefaults standardUserDefaults];
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@YES,@"switch", nil]; [usr registerDefaults:dic];
((UILabel *)self.label).text = [usr boolForKey:@"switch"]?@"开":@"关";
self.switchButton.on = [usr boolForKey:@"switch"];
//都要写入一下
[usr synchronize];
} - (void)viewDidLoad
{
[super viewDidLoad];
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeData) name:UIApplicationWillEnterForegroundNotification object:app];
} - (void)dealloc {
[self.switchButton release];
[_label release];
[super dealloc];
}
//实现协议的方法
- (void)flipsideViewControllerDidFinish:(DXWViewController1 *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)change:(id)sender {
UISwitch *switchButton = sender;
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
[user setBool:switchButton.on forKey:@"switch"];
[user synchronize];
((UILabel *)self.label).text = [user boolForKey:@"switch"]?@"开":@"关";
}
- (IBAction)showInfo:(id)sender {
UIStoryboard *strBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
DXWViewController1 *controller = [strBoard instantiateViewControllerWithIdentifier:@"DXWViewController1"];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}
@end
上图中showInfo方法是通过代码的方法实现跳转到下一个view,如果是通过storyboard实现连线的方法然后跳过下一个view是这样实现:
//连线的方法
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Add"]) {
DXWViewController1 *controlller = segue.destinationViewController;
controlller.delegate = self;
}
}
6.修改DXWViewController1(子视图)
DXWViewController.h:
#import <UIKit/UIKit.h>
@class DXWViewController1; @protocol DXWFlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(DXWViewController1 *)controller;
@end
@interface DXWViewController1 : UIViewController
@property (assign, nonatomic) id <DXWFlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
@end
DXWViewController.m:
#import "DXWViewController1.h" @interface DXWViewController1 () @end @implementation DXWViewController1 - (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.
} - (IBAction)done:(id)sender {
[self.delegate flipsideViewControllerDidFinish:self];
}
@end
[IOS]Setting Bundle + StoryBoard的更多相关文章
- ios创建bundle的图片资源文件(转)
在ios开发中为了方便管理资源文件,可以使用bundle的方式来进行管理,比如kkgridview里就是把所需的图片文件全部放在一个bundle来管理的 . 切记目前iOS中只允许使用bundle管理 ...
- IOS 移除storyboard
我是IOS新手,都说storyboard是个好东西,但是我搞了一会始终没有搞懂,并且我觉得学习一门语言,使用类似以前网页三剑客这种所见所得工具,不太利于学习,所以我就想着移除storyboard 1: ...
- setting bundle 多语言,本地化,系统设置
新建一个setting.bundle后结构如下: Settings.bundle en.lproj Root.strings Root.plist 大家一般都在Root.plst里面添加删除条目,那么 ...
- (11)Xamarin.iOS - 新增iPhone storyboard
原文 Xamarin.iOS - 新增iPhone storyboard 1. 开启Xamarin Studio 并建立新项目 专案类型为 iOS=>iPhone Storyboard => ...
- iOS 7 中 StoryBoard 总体缩放
iOS 7 中 StoryBoard 总体缩放 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用 ...
- iOS多个storyboard间跳转
Stroyboard 可以被看作一个管理View画面的集合.也就是说一个iOS专案裡面并没有限制只能有一个Storyboard.所以在你的APP专案中,你可以把功能相近的View放到同一个APP之中, ...
- iOS - 集成Bundle资源文件包
1.Bundle 文件 Bundle 文件,简单理解,就是资源文件包.我们将许多图片.XIB.文本文件组织在一起,打包成一个 Bundle 文件.方便在其他项目中引用包内的资源. Bundle 文件是 ...
- iOS 疑难杂症 — — 在 Storyboard 里 Add Size Class Customization 后再从代码里无法修改的问题
前言 公司的产品同时适配 iPhone 和 iPad ,并坚持用 Storyboard 来做适配,今天又踩一个坑(以前遇到过)还以为是 XCode 的鬼毛病. 声明 欢迎转载,但请保留文章原始出处: ...
- 【转】iOS学习之Storyboard中的UIScrollView使用自动布局
在使用storyboard和xib时,我们经常要用到ScrollView,还有自动布局AutoLayout,但是ScrollView和AutoLayout 结合使用,相对来说有点复杂.根据实践,我说一 ...
随机推荐
- Hadoop集群配置(最全面总结)
Hadoop集群配置(最全面总结) 通常,集群里的一台机器被指定为 NameNode,另一台不同的机器被指定为JobTracker.这些机器是masters.余下的机器即作为DataNode也作为Ta ...
- 深入解析MFC -- 句柄与对象的关系
CWnd::FromHandlePermanent ——根据窗口句柄得到CWnd*指针 This function, unlike FromHandle, does not create tempor ...
- Delphi发送邮件...
///首先在控件栏定位到:Indy Clients加入控件IdSMTP ///再定位到:Indy Misc加入控件IdMessage ///发送邮件函数 procedure TForm1.SendMa ...
- Mac OSX的开机启动配置
Login Items Mac OSX的当前用户成功登录后启动的程序,该类别的启动项配置文件存放在~/Library/Preferences/com.apple.loginitems.plist,所以 ...
- Hibernate 3中如何获得库表所有字段的名称
15问:Hibernate 3中如何获得库表所有字段的名称 答:可以使用以下的程序获得. Configuration conf = new Configuration(); conf.configur ...
- 用Python做2048游戏 网易云课堂配套实验课。通过GUI来体验编程的乐趣。
第1节 认识wxpython 第2节 画几个形状 第3节 再做个计算器 第4节 最后实现个2048游戏 实验1-认识wxpython 一.实验说明 1. 环境登录 无需密码自动登录,系统用户名shiy ...
- [Boost]boost的时间和日期处理-(1)日期的操作
<开篇> Boost.DateTime库提供了时间日期相关的计算.格式化.转换.输入输出等等功能,为C++的编程提供了便利.不过它有如下特点: 1. Boost.DateTime 只支持1 ...
- P65
#include<stdio.h> #define N 6 main() { char c[N]; int i=0; for(;i<N;c[i]=getchar(),i++); pr ...
- 深入理解mysql之BDB系列(1)---BDB相关基础知识
深入理解mysql之BDB系列(1) ---BDB相关基础知识 作者:杨万富 一:BDB体系结构 1.1.BDB体系结构 BDB总体的体系结构如图1.1所看到的,包括五个子系统(见图1.1 ...
- 超详细SDK Hello World
Windows应用程序的基本运行机制与HelloWin程序详细解 总的来说最基本的Windows应用程序的运行执行顺序总是以如下的基本顺序执行的. 顺序结构: 调用WinMain函数开始执行--à定义 ...