用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. 【转】opencv-在图像上显示字符(不包括中文)

    原文参见:http://blog.csdn.net/ycc892009/article/details/6516528 1 #include <cv.h> #include <hig ...

  2. Maven创建项目: Failed to execute goal org.apache.maven.plugin( mvn archetype:create)

    一.概述: 在使用mvn 命令mvn archetype:create -DgroupId=com.chuanliu.c11 -DartifactId=c11searcher在控制创建maven项目和 ...

  3. hdu 1026 Ignatius and the Princess I【优先队列+BFS】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1026 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  4. BNU 26579 Andrew the Ant 【蚂蚁】

    链接: http://www.bnuoj.com/bnuoj/problem_show.php?pid=26579 http://www.bnuoj.com/bnuoj/contest_show.ph ...

  5. SimpleAdapter

    1.视图 1)主视图 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x ...

  6. PHP - 防止 XSS(跨站脚本攻击)

    <?PHP /** * @blog http://www.phpddt.com * @param $string * @param $low 安全别级低 */ function clean_xs ...

  7. Linux下安装yum工具

    Linux下安装yum工具 http://blog.csdn.net/caoshichaocaoshichao/article/details/13171919

  8. Source Insight使用技巧

    1. source insight必设: option-->key assignments-->    Edit: Delete Line ---- Assign New Key: Ctr ...

  9. android开发过程中遇到的小问题

    ​转自:http://www.sctarena.com/Article/Article.asp?nid=5070​​1.在编写xml布局的时候,总是提示[Accessibility] Missing ...

  10. 【译】在Asp.Net中操作PDF – iTextSharp-列表

    原文 [译]在Asp.Net中操作PDF – iTextSharp-列表 在前文中,我们已经知道了如何利用iTextSharp创建PDF文档,设置字体样式和风格.本文开始讲述iTextSharp中的有 ...