Preference(使用SettingBundle),再利用InAppSettingsKit,放到APP內

Preference(使用SettingBundle),再利用InAppSettingsKit,放到APP內

 ios_pref_main  

下載inAppSettingsKit, 將解壓縮後的資料夾(InAppSettingsKit), 複製至專案檔中。

實作

ios_pref (新增Settings Bundle), 至此Settings Bundle已可使用。

接下來, 介紹Settings Bundle。
ios_pref_intro   
※包進app裡:

以程式方式:
//IASKViewController繼承自IASKAppSettingsViewController並實作了<IASKSettingsDelegate>
IASKViewController *sCtrl = [[IASKViewController alloc]init];
sCtrl.showDoneButton = NO;
//記得要用UINavigationController包起來
UINavigationController *navCtrl = [[UINavigationController alloc]initWithRootViewController:sCtrl];

以Interface-Builder方式
image

取得SettingsBundle值的方式:以Identifier為鍵值,
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *distance = [userDefaults valueForKey:@"pref_distanceFilter"];

隱藏某設定項

IASKAppSettingsViewController *sCtrl = [[IASKAppSettingsViewController alloc]init];
sCtrl.hiddenKeys = [NSSet setWithObjects:@"pref_faq", nil];


Title (顯示版號或是做按鈕)
image 
(按鈕)
image
Toggle Switch
image
Slider

Multi Value
image
Group    
image
Child Pane(可用來做進階設定或是顯示內嵌的網頁)
image 

(內嵌網頁)
image 
繼承的IASKViewController
.h

//
//  IASKViewController.h
//  TpeFree
//
//  Created by Hsuan-ming Yang on 12/12/22.
//
//
 
#import "IASKAppSettingsViewController.h"
 
@interface IASKViewController : IASKAppSettingsViewController<IASKSettingsDelegate, UIAlertViewDelegate>
 
@end

.m

//
//  IASKViewController.m
//  TpeFree
//
//  Created by Hsuan-ming Yang on 12/12/22.
//
//
 
#import "IASKViewController.h"
#import "IASKSpecifier.h"
#import "AppDelegate.h"
@interface IASKViewController ()
{
    AppDelegate *appDelegate_;
}
@property(nonatomic, strong)UIActivityIndicatorView *actIndicator;
@end
 
@implementation IASKViewController
@synthesize actIndicator;
 
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {
        case 1:
            [self performSelector:@selector(updateDataBase) withObject:nil afterDelay:0.5];
            break;
            
        default:
            break;
    }
}
//IASKSettingsDelegate
//Button
-(void)settingsViewController:(IASKAppSettingsViewController *)sender buttonTappedForSpecifier:(IASKSpecifier *)specifier
{
    NSLog(@"%@", specifier.key);
    if ([specifier.key isEqualToString:@"pref_updateData"]) {
        //省略...
    }
}
 
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
{
    
}
 
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
    //隱藏某個設定項
    if(![language isEqualToString:@"zh-Hant"])
        self.hiddenKeys = [NSSet setWithObjects:@"pref_faq", nil];
   //將delegate指向到自己,當IASKButtonSpecifier項目觸發時,
   //Call Back >>>settingsViewController:(IASKAppSettingsViewController *)sender buttonTappedForSpecifier:(IASKSpecifier *)specifier
    self.delegate = self;
    
    appDelegate_ = (AppDelegate*)[UIApplication sharedApplication].delegate;
}
 
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
-(void)viewDidUnload
{
    [self setActIndicator:nil];
    [super viewDidUnload];
}
 
@end