用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是这样实现:

@“Add”是连线的ID
//连线的方法
-(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的更多相关文章

  1. ios创建bundle的图片资源文件(转)

    在ios开发中为了方便管理资源文件,可以使用bundle的方式来进行管理,比如kkgridview里就是把所需的图片文件全部放在一个bundle来管理的 . 切记目前iOS中只允许使用bundle管理 ...

  2. IOS 移除storyboard

    我是IOS新手,都说storyboard是个好东西,但是我搞了一会始终没有搞懂,并且我觉得学习一门语言,使用类似以前网页三剑客这种所见所得工具,不太利于学习,所以我就想着移除storyboard 1: ...

  3. setting bundle 多语言,本地化,系统设置

    新建一个setting.bundle后结构如下: Settings.bundle en.lproj Root.strings Root.plist 大家一般都在Root.plst里面添加删除条目,那么 ...

  4. (11)Xamarin.iOS - 新增iPhone storyboard

    原文 Xamarin.iOS - 新增iPhone storyboard 1. 开启Xamarin Studio 并建立新项目 专案类型为 iOS=>iPhone Storyboard => ...

  5. iOS 7 中 StoryBoard 总体缩放

    iOS 7 中 StoryBoard 总体缩放 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用 ...

  6. iOS多个storyboard间跳转

    Stroyboard 可以被看作一个管理View画面的集合.也就是说一个iOS专案裡面并没有限制只能有一个Storyboard.所以在你的APP专案中,你可以把功能相近的View放到同一个APP之中, ...

  7. iOS - 集成Bundle资源文件包

    1.Bundle 文件 Bundle 文件,简单理解,就是资源文件包.我们将许多图片.XIB.文本文件组织在一起,打包成一个 Bundle 文件.方便在其他项目中引用包内的资源. Bundle 文件是 ...

  8. iOS 疑难杂症 — — 在 Storyboard 里 Add Size Class Customization 后再从代码里无法修改的问题

    前言 公司的产品同时适配 iPhone 和 iPad ,并坚持用 Storyboard 来做适配,今天又踩一个坑(以前遇到过)还以为是 XCode 的鬼毛病. 声明  欢迎转载,但请保留文章原始出处: ...

  9. 【转】iOS学习之Storyboard中的UIScrollView使用自动布局

    在使用storyboard和xib时,我们经常要用到ScrollView,还有自动布局AutoLayout,但是ScrollView和AutoLayout 结合使用,相对来说有点复杂.根据实践,我说一 ...

随机推荐

  1. MVC-01 概述

    一.何谓MVC 1.MVC是开发时所使用的一种架构(框架). 2.目的在于简化软件开发的复杂度,以一种概念简单却又权责分明的架构,贯穿整个软件开发流程,通过“商业逻辑层”与“数据表现层”的切割,让这两 ...

  2. ORACLE存储过程笔记3

    ORACLE存储过程笔记3 流程控制 1.条件   if expression thenpl/sql or sqlend if;   if expression thenpl/sql or sqlel ...

  3. Firemonkey ListBoxItem自绘

    ListBoxItem1的事件ListBoxItem1Paint procedure TForm1.ListBoxItem1Paint(Sender: TObject; Canvas: TCanvas ...

  4. NGUI出现Shader wants normals, but the mesh UIAtlas doesn&#39;t have them

    NGUI出现Shader wants normals, but the mesh UIAtlas doesn't have them,没有网格法线,打开UI Root上 UIPanel组建上的 Nor ...

  5. android蓝牙的调试(博通蓝牙工作 and 低功耗模式)

    首先结合项目从整体上去把握这部分: 蓝牙模块中一个比较核心的文件是bluetooth.c, 在我们上电的时候, 会调用这个文件中bt_enable()这个函数, 在这个函数里面先调用set_bluet ...

  6. SUSAN检测算子

    USAN区域(核同值区):和核像素的灰度相同会相信的模板像素的区域. 利用这个区域的尺寸.重心.二阶矩等可以帮助检测图像的边缘和角点.利用USAN的面积作为特征可以起到增强边缘和角点的效果. 该方法不 ...

  7. Python 第七篇:异步IO\数据库\队列\缓存

    Gevent协程 Select\Poll\Epoll异步IO与事件驱动 Python连接Mysql数据库操作 RabbitMQ队列 Redis\Memcached缓存 Paramiko SSH Tws ...

  8. Android 关于网址,电话号码,邮箱的正则表达式-最权威

    需求:判断网址是否合法 今天在写一个项目的时候,需要能够识别网址的功能,首先想到的是正则表达式 但是网址的类型多种多样,网络上各种表达式也一搜一大把,很难知道哪一位大神写的靠谱 发现:TextView ...

  9. 设计模式(五)适配器模式Adapter(结构型)

      设计模式(五)适配器模式Adapter(结构型) 1. 概述: 接口的改变,是一个需要程序员们必须(虽然很不情愿)接受和处理的普遍问题.程序提供者们修改他们的代码;系统库被修正;各种程序语言以及相 ...

  10. bzoj 1901: Zju2112 Dynamic Rankings(树套树)

    1901: Zju2112 Dynamic Rankings 经典的带改动求区间第k小值问题 树套树模板,我是用的线段树套splay实现的,并且用的数组模拟的,所以可能空间略大,bzoj过了,zoj过 ...