当前位置: 首页 > news >正文

网站制作的建设大纲ppt信誉好的大连网站建设

网站制作的建设大纲ppt,信誉好的大连网站建设,网站升级页面连接设置,网站推广网络创建一个Demo来学习一个Setting Bundle为程序存储设置项 Settings Bundle是在自己的程序中建立的一组文件#xff0c;利用它可以告诉设备中的Settings程序我们写的程序有哪些设置项。用户在Settings程序中设置好相关相关选项后回到我们自己的程序#xff0c;自己的程序中的对… 创建一个Demo来学习一个Setting Bundle为程序存储设置项 Settings Bundle是在自己的程序中建立的一组文件利用它可以告诉设备中的Settings程序我们写的程序有哪些设置项。用户在Settings程序中设置好相关相关选项后回到我们自己的程序自己的程序中的对应项也会发生相应的变化。 在iOS程序中用户默认项即上面所说的设置项是用NSUserDefaults类实现的。在NSUserDefaults类中使用关键字来读取和存储设置项的具体数据就像NSDictionary类一样不同的是NSUserDefaults类的数据是存储在文件系统中的而不是作为一个对象实例放在内存中。 在这篇文章中我们将创建一个程序为它添加和配置Settings Bundle之后可以在Settings程序中显示和配置相关选项。在Settings Bundle中使用plist文件来定义程序中允许的设置项Settings程序会自动建立接口。Settings Bundle中的plist文件必须遵循特定的格式不过Xcode会帮助我们遵循这种格式。 实现步骤 1、首先下载初始代码。http://www.oschina.net/code/snippet_164134_10458 由于我们的重点是Settings Bundle的使用那么建立工程、实现页面跳转等等就不详细说明了。 2、解压Settings Bundle Test.zip使用Xcode 4.3打开此工程先打开FirstViewController.xib使用IB向其中添加控件如下图 然后为这些标签向FirstViewController.h中建立Outlet映射 3、打开MoreViewController.xib向其中添加控件如下 然后向MoreViewController.h中为右边的两个Label以及UISlider与UISWitch控件创建Outlet映射为UISlider与UISWitch控件添加Action映射 然后在Attribute Insepector中设置UISlider控件最小值、最大值和默认值分别是0、10和5 将准备好的两张图片添加到工程中在Attribute Insepector中设置UISlider控件的Min Image与Max Image 4、接下来为程序建立Settings Bundle。依次选择File — New — File…找到Settings Bundle 单击Next设置好名称和分组 然后单击Create则创建了Settings.bundle。 5、展开Settings.bundle其中包含一个Root.plist。Settings程序中的显示项就是从Root.plist中获取的。 单击Root.plist以打开它在空白处单击选中Show Raw Keys/Values 接下来我们展开PreferenceSpecifiers那一项删除除了Group之外的其他项。 PreferenceSpecifiers这个对应于刚打开Settings程序时第一页中该应用程序的一个标签如果此时运行程序然后在模拟器返回桌面再打开Settings程序则其中会出现Settings Bundle Test这一项 上图中的Settings Bundle Test这一项就可以理解为是从PreferenceSpecifiers获取的。 6、展开PreferenceSpecifiers这一项先向其中添加三行每一行的设置如下 此时运行程序在Settings程序中单击上图中的Settings Bundle Test那一项出现的页面如下图     在Root.plist文件中Item 0那一项的类型是PSGroupSpecifier它表示一个分组则它下面的每Item 1到Item 3都是在这一组直到下一个PSGroupSpecifier出现。 Item 1与Item 2都是PSTextFieldSpecifier类型的它们都是文本框可以通过为其添加子项限制这些文本框的输入。 Item 3是一个多选框可供选择的值是由Titles与Values决定的Titles与Values这两项内容是一样的但是缺一不可。 7、之后再向其中添加Item 4到Item 7如下图 再运行程序打开Settings程序看看     8、之后我们实现在上面左图的下方出现一项“更多设置”单击此项跳转到新的页面。先创建一个plist文件名称为MoreSettings.plist创建方法就不说了吧参考http://my.oschina.net/plumsoft/blog/42084第二步。注意现在只是创建到工程中而不是Settings.bundle中想要加到Settings.bundle中还要其他操作稍后详解。 右击Settings.bundle选择Show in Finder 然后在Finder中右击Settings.bundle选择“显示包含内容” 在打开的地方将MoreSettings.plist以及上面用到的两张图片拷贝进去。 9、编辑Settings.bundle中的MoreSettings.plist内容如下 保存后在Root.plist添加一行 注意Item 8的类型是通过选择其子选项Type的类型改变的。 此时运行程序Settings程序如下     10、接下来都是代码了。 10.1 在ViewController.h中添加代码 #define kUserName username #define kPassWord password #define kGender gender #define kFavouriteColor favouritecolor #define kFavouriteSeason favouriteseason #define kFavouriteSport favouritesport #define kTheSlider theslider #define kTheSwitch theswitch 10.2 在FirstViewController.h与MoreViewController.h中分别声明一个方法名为 - (void)refreshFields; 在FirstViewController.m中添加代码如下 - (void)refreshFields { NSUserDefaults *defaults [NSUserDefaults standardUserDefaults]; self.userNameLabel.text [defaults objectForKey:kUserName]; self.passWordLabel.text [defaults objectForKey:kPassWord]; self.genderLabel.text [defaults objectForKey:kGender]; self.colorLabel.text [defaults objectForKey:kFavouriteColor]; self.seasonLabel.text [defaults objectForKey:kFavouriteSeason]; self.sportLabel.text [defaults objectForKey:kFavouriteSport]; } 在MoreViewController.m中添加代码如下 - (void)refreshFields { NSUserDefaults *defaults [NSUserDefaults standardUserDefaults]; self.theSwitch.on [defaults boolForKey:kTheSwitch]; self.slider.value [defaults floatForKey:kTheSlider]; self.sliderValueLabel.text [[defaults objectForKey:kTheSlider]stringValue]; } 10.3 实现MoreViewController.m中的sliderTapped与switchTapped方法如下 - (IBAction)sliderTapped:(id)sender { NSUserDefaults *defaults [NSUserDefaults standardUserDefaults]; [defaults setFloat:self.slider.value forKey:kTheSlider]; self.sliderValueLabel.text [[defaults objectForKey:kTheSlider] stringValue]; [defaults synchronize]; } - (IBAction)switchTapped:(id)sender { NSUserDefaults *defaults [NSUserDefaults standardUserDefaults]; [defaults setBool:self.theSwitch.on forKey:kTheSwitch]; [defaults synchronize]; } 10.4 在FirstViewController.m与MoreViewController.m中end之前都添加代码 - (void)applicationWillEnterForeground:(NSNotification *)notification { NSUserDefaults *defaults [NSUserDefaults standardUserDefaults]; [defaults synchronize]; [self refreshFields]; } 10.5 在FirstViewController.m与MoreViewController.m的viewDidLoad方法中都添加代码 [self refreshFields]; UIApplication *app [UIApplication sharedApplication]; [[NSNotificationCenter defaultCenter] addObserver:self selector:selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:app]; 10.6 在FirstViewController.m与MoreViewController.m中的ViewDidUnload方法中都添加代码 [[NSNotificationCenter defaultCenter] removeObserver:self]; 11.7 在ViewController.m的viewDidLoad方法中的[super viewDidLoad];之前添加代码 //注册默认项 NSDictionary *defaults [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], kTheSwitch, [NSNumber numberWithFloat:5.0], kTheSlider, nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:defaults]; 11、运行那么Settings Bundle Test程序中的数据将会随着Settings程序中的选项改变而改变反过来也是。 例如在Settings程序中设置如下     返回Settings Bundle Test程序显示如下     不过第一次运行程序时单击“更多设置”按钮Slider与Switch是变形的然后才会显示正确的值 真是好事多磨啊。 刚运行程序第一次单击“更多设置”按钮就会出现上图情况。猜想是因为刚开始ViewController中的moreViewController为空在页面跳转时才创建它。为此试试在ViewController.m的viewDidLoad方法的最后一条语句之前添加代码 self.moreViewController [[MoreViewController alloc] initWithNibName:MoreViewController bundle:nil]; self.moreViewController.viewController self; 再运行试试还是不行。那估计是跟页面跳转时的动态效果有关了。再把ViewController.m的switchViews方法修改如下 - (void)switchViews { if (self.moreViewController.view.superview nil) { if (self.moreViewController nil) { self.moreViewController [[MoreViewController alloc] initWithNibName:MoreViewController bundle:nil]; self.moreViewController.viewController self; } } else { if (self.firstViewController nil) { self.firstViewController [[FirstViewController alloc] initWithNibName:FirstViewController bundle:nil]; self.firstViewController.viewController self; } } [UIView beginAnimations:View Flip context:nil]; [UIView setAnimationDuration:0.80]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; if (self.moreViewController.view.superview nil) { [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; [self.firstViewController.view removeFromSuperview]; [self.view insertSubview:self.moreViewController.view atIndex:0]; } else { [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; [self.moreViewController.view removeFromSuperview]; [self.view insertSubview:self.firstViewController.view atIndex:0]; } [UIView commitAnimations]; } 再运行问题总算解决了。 最终代码http://www.oschina.net/code/snippet_164134_10484 ------------------------------------------------------------------------------------- 另外一个demo实现步骤 1.创建一个Utility Application。 2.同样创建Settings Bundle文件。 3.点击Root.plist-showRowKeys/Values,看看对应的每个key值后面在代码预定义的时候要写的key跟这个要一模一样的NSUserDefault中自动创建的文件必须要等setting或者view中相应的值改了以后才能产生一个key/value记录。 4.修改MainViewController中的代码 MainViewController.h: #import DXWFlipsideViewController.h interface DXWMainViewController : UIViewController DXWFlipsideViewControllerDelegate - (IBAction)showInfo:(id)sender; property (retain, nonatomic) IBOutletCollection(UILabel) NSArray *labels; property (retain, nonatomic) IBOutlet UISwitch *switchButton; - (IBAction)change:(id)sender; end MainViewController.m: #import DXWMainViewController.h interface DXWMainViewController () end implementation DXWMainViewController -(void)viewWillAppear:(BOOL)animated { [self changeData]; } -(void)changeData { NSUserDefaults *usr [NSUserDefaults standardUserDefaults]; NSDictionary *dic [NSDictionary dictionaryWithObjectsAndKeys:ding,name,YES,switch,0.4,slider,nil]; //在当前的userDeafults注册一个 [usr registerDefaults:dic]; ((UILabel *)self.labels[0]).text [usr objectForKey:name]; ((UILabel *)self.labels[1]).text [usr boolForKey:switch]?开:关; ((UILabel *)self.labels[2]).text [NSString stringWithFormat:%f,[usr floatForKey:slider]]; 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]; } #pragma mark - Flipside View - (void)flipsideViewControllerDidFinish:(DXWFlipsideViewController *)controller { [self dismissViewControllerAnimated:YES completion:nil]; } - (IBAction)showInfo:(id)sender { DXWFlipsideViewController *controller [[[DXWFlipsideViewController alloc] initWithNibName:DXWFlipsideViewController bundle:nil] autorelease]; controller.delegate self; controller.modalTransitionStyle UIModalTransitionStyleFlipHorizontal; [self presentViewController:controller animated:YES completion:nil]; } - (void)dealloc { [_labels release]; [_switchButton release]; [super dealloc]; } - (IBAction)change:(id)sender { UISwitch *switchButton sender; NSUserDefaults *user [NSUserDefaults standardUserDefaults]; [user setBool:switchButton.on forKey:switch]; [user synchronize]; ((UILabel *)self.labels[1]).text [user boolForKey:switch]?开:关; } end 本文转蓬莱仙羽51CTO博客原文链接http://blog.51cto.com/dingxiaowei/1366406如需转载请自行联系原作者
http://www.yutouwan.com/news/211738/

相关文章:

  • 企业网站建设目的选择题高端电商设计公司
  • 以下哪一项不属于seo对网站推广的作用wordpress 2.0 下载地址
  • 优化网站排名怎么制作wordpress支付宝微信收费
  • 目前最好的免费网站国内最新新闻10条
  • 做网站语言南昌做seo的公司有哪些
  • 网站开发的项目总结用软件做网站
  • 自己的电脑建网站开发网站需要什么硬件
  • 做企业网站的费用软件开发行业市场分析
  • 重庆荣昌网站建设公司网站首页制作方案
  • 一个备案号多个网站简述建设一个网站的具体过程
  • 网站权重排行WordPress访问mysql慢
  • 深圳专业手机网站建设输入关键词自动生成标题
  • 连云港网站关键字优化市场网站右下角图片广告代码
  • 温州自助模板建站买国外空间哪个网站好
  • 网站投票怎么做某景区网站建设策划书
  • 网站建设期末试题天猫店铺申请条件及费用
  • 石家庄哪里能做门户网站的想学设计师首先要学什么
  • 番禺高端网站建设网站优化 图片
  • 安徽制作网站专业公司wordpress登录可见
  • 南通企业网站公司策划是做什么的
  • 在线销售型网站产品蓬莱做网站那家好
  • 网站同时使用asp php钢结构招聘网最新招聘信息
  • 微网站是免费的吗页面跳转自动更新
  • 怎么给网站做链接屏蔽微信网址
  • 青岛大型门户网站建设推广南京房地产网站建设
  • 张家口北京网站建设打不开网站怎么办
  • 郑州网站建设费用滴道网站建设
  • 网站开发自学网校园文化建设
  • 东莞网站建设效果淘宝网网页版登录官网登录
  • 怎么从网站知道谁做的公司网站网页设计