简体   繁体   中英

Sending a parameter (or get the key) with inAppSettingsKit when initialising custom controller

I'm trying to initialise a custom viewcontroller and send a parameter with it but can't figure it out.

To sketch an idea:

I want to have different settings per sport (walking, running, ...) and save those in core data on the custom viewcontroller.

To know to which sport the settings belong to I need to know what sport the user tapped to get to that screen. I was thinking about doing this by sending a parameter, using a custom init for each sport or by getting the key. All of which I can't figure out.

I've looked into this issue and tried to do it like this: (item 4) 在此处输入图片说明 But that doesn't work, according to the IASK docs I think I also need to specify a file, but what file?

The selector must have two arguments: an NSString argument for the file name in the Settings bundle and the IASKSpecifier.

I've tried setting a File field and tried different values but without success.

I'm seriously lost here, if it's possible to get the key of the item that initialised the controller ("running" for item 4 for example) that would also be good.

I've tried so many different things I'm losing my mind, I'm obviously doing something very wrong but I have no idea what it is.

You don't need to specify an IASKSpecifier key in your Settings.plist . The way this works is you implement

SettingsPerSportViewController.m :

- (id) myinit:(NSString*)file specifier:(IASKSpecifier*)specifier {
    if ((self = [super init])) {
        // setup your VC
        if ([specifier.key isEqualToString:@"tennis"]) {
            // custom stuff for tennis
        } 
    }
    return self;
}

However, this means you build the settings view controllers for your sports on your own and don't use IASK for that.

If all sports share the same settings and you want to use IASK to generate the settings view controller, you could implement a custom settings storage and use the same Sport.plist for all sports. Your custom settings storage could then load from and save directly to Core Data. A sport property would then route the load and save operations to the right Core Data context or table.

At the root level you could have a simple static view controller that sets up and pushes an IASKAppSettingsViewController for each sport with the settingsStore property set to your custom storage subclass and the sport property set according to the selected sport.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM