用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. Spring IOC三种注入方式(接口注入、setter注入、构造器注入)(摘抄)

    IOC ,全称 (Inverse Of Control) ,中文意思为:控制反转, Spring 框架的核心基于控制反转原理. 什么是控制反转?控制反转是一种将组件依赖关系的创建和管理置于程序外部的技 ...

  2. c# 数据库编程(通过SqlCommand 执行DML语句)

    原来一直是java,python等语言,最近用c#语言,并编写数据库访问代码.使用了之后,这里总结下,分享下c#如何操作数据库. 在java等其它语言中,有一套标准的api来完成数据库访问,并且一般都 ...

  3. java邮件小实例

    新建一个包,名为mail 第一个类:MailSenderInfo.java  ########################################### package com.util. ...

  4. vc中关于 directx的配置,和dxsdk_extras(directshow)

      2009-11-10 0:28 此文章:自己编写 转载于<汤姆&杰瑞> DirectShow 1 -- 下载与VC配置 1 DirectX SDK9 Directshow sd ...

  5. webform--常用的控件

    一.简单控件 1.Lable——标签:在网页中呈现出来的时候会变成span标签 属性:Text——标签上的文字  BackColor,ForeColor——背景色,前景色 Font——字体 Bold- ...

  6. IOS_Note

    关键字:可以搜索这些关键字找到具体内容 退回输入键盘.CGRect.CGPoint & CGSize.设置透明度.设置背景色.自定义颜色. 竖屏.横屏.状态栏高  (显示时间和网络状态). 导 ...

  7. mockito中两种部分mock的实现,spy、callRealMethod

    什么是类的部分mock(partial mock)?A:部分mock是说一个类的方法有些是实际调用,有些是使用mockito的stubbing(桩实现). 为什么需要部分mock? A:当需要测试一个 ...

  8. Login oracle for external authenticate

    Generally, we can login the oracle by os authentication, if we login os in a remote machine and make ...

  9. Jump的计划

    欢迎訪问我的github:https://github.com/xdnm 1.熟悉cocos2dx2.2.3开发框架 a.熟悉cocos2d api                           ...

  10. traceroute工作原理

      traceroute, 也就是 trace route,跟踪路由.这个程序最早是Van Jacobson实现的.源代码在网上能够找到,只是我还没有去找.基本的原理是IP路由过程中对数据包TTL(T ...