0
對於Iphone應用程序,我嘗試實現InAppSettingsKit(tabbar版本)。我成功地將庫樣本集成到我的應用程序中,但不調用「settingsViewController」方法。 這是我的代碼:InAppSettingsKit Tabbar,不調用settingsViewController
.H
#import "InAppSettingsKit/IASKAppSettingsViewController.h"
@interface Settings : IASKAppSettingsViewController
@end
.M
#import "Settings.h"
#import <MessageUI/MessageUI.h>
#import "InAppSettingsKit/IASKSpecifier.h"
#import "InAppSettingsKit/IASKSettingsReader.h"
#import "CustomViewCell.h"
@interface Settings()
- (void)settingDidChange:(NSNotification*)notification;
@end
@implementation Settings
- (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.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
BOOL enabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"AutoConnect"];
self.hiddenKeys = enabled ? nil : [NSSet setWithObjects:@"AutoConnectLogin", @"AutoConnectPassword", nil];
self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark IASKAppSettingsViewControllerDelegate protocol
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender {
[self dismissModalViewControllerAnimated:YES];
// your code here to reconfigure the app for changed settings
}
// optional delegate method for handling mail sending result
- (void)settingsViewController:(id<IASKViewController>)settingsViewController mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if (error != nil) {
// handle error here
}
if (result == MFMailComposeResultSent) {
// your code here to handle this result
}
else if (result == MFMailComposeResultCancelled) {
// ...
}
else if (result == MFMailComposeResultSaved) {
// ...
}
else if (result == MFMailComposeResultFailed) {
// ...
}
}
- (CGFloat)settingsViewController:(id<IASKViewController>)settingsViewController
tableView:(UITableView *)tableView
heightForHeaderForSection:(NSInteger)section {
NSString* key = [settingsViewController.settingsReader keyForSection:section];
if ([key isEqualToString:@"IASKLogo"]) {
return [UIImage imageNamed:@"imager.png"].size.height + 25;
} else if ([key isEqualToString:@"IASKCustomHeaderStyle"]) {
return 55.f;
}
return 0;
}
- (UIView *)settingsViewController:(id<IASKViewController>)settingsViewController
tableView:(UITableView *)tableView
viewForHeaderForSection:(NSInteger)section {
NSString* key = [settingsViewController.settingsReader keyForSection:section];
if ([key isEqualToString:@"IASKLogo"]) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconr.png"]];
imageView.contentMode = UIViewContentModeCenter;
return imageView;
} else if ([key isEqualToString:@"IASKCustomHeaderStyle"]) {
UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor redColor];
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0, 1);
label.numberOfLines = 0;
label.font = [UIFont boldSystemFontOfSize:16.f];
//figure out the title from settingsbundle
label.text = [settingsViewController.settingsReader titleForSection:section];
return label;
}
return nil;
}
- (CGFloat)tableView:(UITableView*)tableView heightForSpecifier:(IASKSpecifier*)specifier {
if ([specifier.key isEqualToString:@"customCell"]) {
return 44*3;
}
return 0;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForSpecifier:(IASKSpecifier*)specifier {
CustomViewCell *cell = (CustomViewCell*)[tableView dequeueReusableCellWithIdentifier:specifier.key];
if (!cell) {
cell = (CustomViewCell*)[[[NSBundle mainBundle] loadNibNamed:@"CustomViewCell"
owner:self
options:nil] objectAtIndex:0];
}
cell.textView.text= [[NSUserDefaults standardUserDefaults] objectForKey:specifier.key] != nil ?
[[NSUserDefaults standardUserDefaults] objectForKey:specifier.key] : [specifier defaultStringValue];
cell.textView.delegate = self;
[cell setNeedsLayout];
return cell;
}
#pragma mark kIASKAppSettingChanged notification
- (void)settingDidChange:(NSNotification*)notification {
if ([notification.object isEqual:@"AutoConnect"]) {
IASKAppSettingsViewController *activeController = self;
BOOL enabled = (BOOL)[[notification.userInfo objectForKey:@"AutoConnect"] intValue];
[activeController setHiddenKeys:enabled ? nil : [NSSet setWithObjects:@"AutoConnectLogin", @"AutoConnectPassword", nil] animated:YES];
}
}
#pragma mark UITextViewDelegate (for CustomViewCell)
- (void)textViewDidChange:(UITextView *)textView {
[[NSUserDefaults standardUserDefaults] setObject:textView.text forKey:@"customCell"];
[[NSNotificationCenter defaultCenter] postNotificationName:kIASKAppSettingChanged object:@"customCell"];
}
#pragma mark -
- (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier {
if ([specifier.key isEqualToString:@"ButtonDemoAction1"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Demo Action 1 called" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
} else if ([specifier.key isEqualToString:@"ButtonDemoAction2"]) {
NSString *newTitle = [[[NSUserDefaults standardUserDefaults] objectForKey:specifier.key] isEqualToString:@"Logout"] ? @"Login" : @"Logout";
[[NSUserDefaults standardUserDefaults] setObject:newTitle forKey:specifier.key];
}
}
@end
如果你的意思是添加IASKSettingsDelegate到。 – 2013-04-23 08:56:16
Ivan,要添加一個委託,在.h文件中聲明協議構造是不夠的。看到我更新的答案。 Signare,而不是抨擊試圖幫助的人,歡迎您發佈自己的答案! – 2013-04-23 09:04:57
我已將此代碼添加到.h: 界面設置:IASKAppSettingsViewController {0} {0}設置* settingsViewController; } property(nonatomic,retain)IBOutlet設置* settingsViewController;我已經添加了綜合settingsViewController;和你的代碼.m但我無法連接我的Storyboard中的IBOutlet(Storyboard中的「表格視圖控制器」有自定義類:設置) –
2013-04-23 13:04:48