1

I am using InAppSettingsKit to include preferences inside my app. I configured the preferences view using xcode's storyboard with the following simple steps:

1) I created a navigation controller and a table view controller
2) In the table controller I used the custom class: IASKAppSettingsViewController, as the controller.

Everything works as expected BUT now I am trying to reconfigure the app so that the settings that the user changed take effect after leaving the settings screen.

One tutorial I found says that I should:

Create a delegate that conforms to the IASKSettingsDelegate protocol. In the current version, -settingsViewControllerDidEnd: is the only required method.

so the delegate should have a method like:

- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender {
    [self dismissModalViewControllerAnimated:YES];
    [self reconfigure];
}

How can I create this delegate? I do not know where to put this method. I can see in the storyboard connection inspector that there is a space for the delegate but I have not been able to connect it. Please help me figuring this out because I have read tons of tutorials explaining delegates and they confused me more. I just need simple steps on how to create a delegate and connect it to the controller I created in the storyboard.

Thank you!

F. A
  • 111
  • 1
  • 10

1 Answers1

2

I have made some advances (but there is one problem). This is what I did:

Instead of using IASKAppSettingsViewController as the class of my controller, I created another class that inherits from IASKAppSettingsViewController. I called it SettingsController

SettingsController.h

#import <UIKit/UIKit.h>
#import "IASKAppSettingsViewController.h"

@interface SettingsController : IASKAppSettingsViewController <IASKSettingsDelegate>
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender;
@end

SettingsController.m

...
@implementation SettingsController
...
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.delegate = self;
    self.showDoneButton = YES;
}
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender {
    // reconfigure code here
}
@end

So basically, I did not make any delegate connection using the storyboard. I had to write <IASKSettingsDelegate> in the controller, and used self.delegate = self; in viewDidLoad method.

The thing is that for the reconfiguration to work, I would need the main view controller to be the delegate (not the settingscontroller). I have not been able to do that. Any help?

Second try: Ok, so now I trie using:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"settingsSegue"])
    {
        [[segue destinationViewController] setDelegate:self];
    }
}

But it does not work. I believe it is because the destinationViewController is a navigationController in the storyboard that immediately displays the table view controller where the settings are.

F. A
  • 111
  • 1
  • 10