Connect IASKAppSettingsView to tabbar item

2019-08-02 07:36发布

问题:

For a iPhone app I'm working on I want to use InAppSettingsKit to handle all the settings from within the app: http://www.inappsettingskit.com/ The sample app runs without problems but I'm not sure how to use it in my own app. There seems to be not documentation.

I have a tabbar item called settings that should display the InAppSettingsKit. When I set the NIB name of the tabbar item to "IASKAppSettingsView" I only get errors. I've looked at the sample code but I can't find out how they connected the view, as their NIB name is empty. Even if I put some meaningless code in that field it still shows the IASKAppSettingsView without errors at all.

Does anyone know how to connect this tabbar item to the IASKAppSettingsView or could point me at some documentation or tutorials as I wasn't able to find them. Thanks!

回答1:

I succeeded in doing what you need by copying and pasting some code from the sample app. Here is what worked for me:

   nav3.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"My title" image:[UIImage imageNamed:@"tabbar_icon_settings.png"] tag:0];

IASKAppSettingsViewController *settings = [[IASKAppSettingsViewController alloc] initWithNibName:@"IASKAppSettingsView" bundle:nil];
//settings.delegate = self;
settings.showDoneButton = NO;
[nav3 pushViewController:settings animated:NO];
[settings release];

UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = [NSArray arrayWithObjects:..., nav3, nil];

Of course you need to properly release and retain your stuff. Notice that "My title" is overwritten by "Settings" which is I suppose set by IASK somewhere. What I use is the pushed-in-navigator version, there is also a modal way to do it in the sample.



回答2:

I solved it by extending IASKAppSettingsViewController like so:

@interface YourSettingsVC : IASKAppSettingsViewController
    // some header stuff
@end

This class must override viewDidLoad: to manually instantiate self.tableView with grouped style. Otherwise it will default to UITableViewStylePlain.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
}

This way I can easily add it as a custom view controller as one of the tabs in my UITabBarController located in my MainWindow.xib. No additional code necessary!