【问题标题】:InAppSettingsKit Tabbar, doesn't call settingsViewControllerInAppSettingsKit 标签栏,不调用 settingsViewController
【发布时间】:2013-04-23 07:03:41
【问题描述】:

对于 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

【问题讨论】:

    标签: iphone ios uitabbar inappsettingskit


    【解决方案1】:

    您是否设置了IASKSettingsDelegate 委托?

    有点像

    self.settingsviewController.delegate = self;
    

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

    【讨论】:

    • 如果你的意思是添加 IASKSettingsDelegate 到 .h ex: @interface Settings : IASKAppSettingsViewController ,我试过了,但是没有用。
    • Ivan,要添加一个委托,在 .h 文件中声明协议构造是不够的。请参阅我的更新答案。 Signare,不要抨击试图提供帮助的人,而是欢迎您发布自己的答案!
    • 我已将此代码添加到 .h : interface Settings : IASKAppSettingsViewController { Settings *settingsViewController; } 属性(非原子,保留) IBOutlet 设置 *settingsViewController;我添加了综合 settingsViewController;和你的代码到 .m 但我无法在我的 Storyboard 中连接 IBOutlet(Storyboard 中的“表格视图控制器”有自定义类:设置)
    • 刚刚注意到您使用的是IASKAppSettingsViewController 的子类。这通常不是必需的或有用的。通常,您只需将&lt;IASKSettingsDelegate&gt; 协议添加到管理IASK 的控制器。在您的情况下,可能是您的根视图控制器。我建议检查示例应用程序以了解所有设置。
    • 我按照question 在库示例中只实现了tabbar,没有其他两种模式。如果没有问题的方法,我无法弄清楚如何将标签栏与其他所有内容分开。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-05
    • 1970-01-01
    • 1970-01-01
    • 2020-08-31
    • 2018-01-20
    相关资源
    最近更新 更多