[Objective-C] iphone读取和写入用户偏好的代码 →→→→→进入此内容的聊天室

来自 , 2021-03-07, 写在 Objective-C, 查看 122 次.
URL http://www.code666.cn/view/5637f327
  1. //
  2. //  SetPrefsAppDelegate.h
  3. //
  4. #import <UIKit/UIKit.h>
  5.  
  6. @interface SetPrefsAppDelegate : NSObject <UIApplicationDelegate>
  7. {
  8.   BOOL        saveUsername;
  9.   NSInteger   preferredIndexInTabbar;
  10.   UIWindow    *window;
  11. }
  12.  
  13. @property (nonatomic, retain) IBOutlet UIWindow *window;
  14.  
  15. @end
  16.  
  17.  
  18. //  SetPrefsAppDelegate.m
  19. //
  20. #import "SetPrefsAppDelegate.h"
  21. #import "Preferences.h"
  22.  
  23. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. // App Delegate implementation
  25. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. @implementation SetPrefsAppDelegate
  27.  
  28. @synthesize window;
  29.  
  30. /*------------------------------------------------------
  31. * Read preferences from system
  32. *-----------------------------------------------------*/
  33. -(void) loadPreferences
  34. {
  35.   saveUsername = [Preferences shouldSaveUsername];
  36.   preferredIndexInTabbar = [Preferences startupTab];
  37. }
  38.  
  39. /*------------------------------------------------------
  40. * Application startup code
  41. *-----------------------------------------------------*/
  42. - (void)applicationDidFinishLaunching:(UIApplication *)application
  43. {  
  44.   // Load user preferences (notice the default values the first time through)
  45.   [self loadPreferences];
  46.  
  47.   // Show the current values of the preferences
  48.   NSLog(@"Save user preferences: %s", saveUsername == YES ? "Yes" : "No");
  49.   NSLog(@"Preferred startup tab: %d", preferredIndexInTabbar);
  50.  
  51.   // This is a little contrived, but you get the point...
  52.   BOOL saveUname = YES;
  53.   NSInteger index = 3;
  54.  
  55.   // Write new values to the sytem
  56.   [Preferences setPreferences:saveUname startupTab:index];
  57.  
  58. //  NSLog(@"Home: %s", NSHomeDirectory());
  59. //  NSLog(@"Home: %@", NSHomeDirectory());
  60.  
  61.   // Override point for customization after application launch
  62.   [window makeKeyAndVisible];
  63. }
  64.  
  65. - (void)dealloc
  66. {
  67.   [window release];
  68.   [super dealloc];
  69. }
  70.  
  71. @end
  72. //objectc/4009

回复 "iphone读取和写入用户偏好的代码"

这儿你可以回复上面这条便签

captcha