[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 结合使用,相对来说有点复杂.根据实践,我说一 ...
随机推荐
- JS 切换显示
<style> #hhh div { width:200px; height:200px; background:red; display:none; ...
- Axis2(9):编写Axis2模块(Module)
Axis2可以通过模块(Module)进行扩展.Axis2模块至少需要有两个类,这两个类分别实现了Module和Handler接口.开发和使用一个Axis2模块的步骤如下: 1. 编写实现Module ...
- Linux下tcpdump用法
根据使用者的定义对网络上的数据包进行截获的包分析工具.tcpdump将网络中传送的数据包的“头”完全截获下来提供分析.它支持针对网络层.协议.主机.网络或端口的过滤,并提供了and. or.not等逻 ...
- 第一次PS练习
嘿嘿,自己第一次的PS,虽然把在大神眼里是小KS,但是了,对我来说值得劲纪念.加油,我会努力的.
- weblogic中设置数据源的注意点
一.基本概念 进入weblogic的管理页面,点击服务——>数据源,可以进行数据源的配置.通过新建,输入地址,用户名,密码等信息可以新建一个数据源. 二.发现问题 建立好数据源之后,跑项目,发现 ...
- Python 第五篇(下):系统标准模块(shutil、logging、shelve、configparser、subprocess、xml、yaml、自定义模块)
目录: shutil logging模块 shelve configparser subprocess xml处理 yaml处理 自定义模块 一,系统标准模块: 1.shutil:是一种高层次的文件操 ...
- 10 - 应用程序间通信、本地通知、加速计、URL传输中文
一.应用间通信 URL 调用系统服务: tel:11111 sms:xxx@163.com http:// URL深入 类型://主机:端口/地址?参数 label框等于文字大小快捷键:command ...
- [置顶] 编程模仿boost::function和boost::bind
boost::function和boost::bind结合使用是非常强大的,他可以将成员函数和非成员函数绑定对一个对象上,实现了类似C#的委托机制.委托在许多时候可以替代C++里面的继承,实现对象解耦 ...
- window批处理-3.go
go: 控制批处理中的命令运行流程 命令格式: go label lable--行号 demo bat @echo off echo 跳过中间.运行最后 goto last type a.txt :l ...
- Java中的字符串驻留
转自:http://www.cdtarena.com/javapx/201307/9088.html 最近在工作的时候,一句再正常不过的代码String a = “hello” + “world”;被 ...