gpt4 book ai didi

iphone - InAppSettingsKit Tabbar,不调用settingsViewController

转载 作者:行者123 更新时间:2023-11-29 03:58:41 28 4
gpt4 key购买 nike

对于 Iphone 应用程序,我尝试实现 InAppSettingsKit(标签栏版本)。我成功将库示例集成到我的应用程序中,但未调用“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 委托(delegate)?

类似

self.settingsviewController.delegate = self;

在你的viewDidLoad中。当然,您需要在 XIB 或 Storyboard 中连接的 settingsViewController 的 IBOutlet 属性。

关于iphone - InAppSettingsKit Tabbar,不调用settingsViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16162997/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com