mirror of
https://github.com/libretro/RetroArch
synced 2025-03-01 07:13:35 +00:00
ios: Make the boolean switches in the settings screen work.
This commit is contained in:
parent
98990ce330
commit
4a8831cbdd
@ -6,8 +6,11 @@
|
|||||||
// Copyright (c) 2013 RetroArch. All rights reserved.
|
// Copyright (c) 2013 RetroArch. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import <objc/runtime.h>
|
||||||
#include "config_file.h"
|
#include "config_file.h"
|
||||||
|
|
||||||
|
static const char* const SETTINGID = "SETTING";
|
||||||
|
|
||||||
static NSString* get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue)
|
static NSString* get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue)
|
||||||
{
|
{
|
||||||
NSString* value = nil;
|
NSString* value = nil;
|
||||||
@ -165,6 +168,11 @@ static NSMutableDictionary* subpath_setting(config_file_t* config, NSString* nam
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
[self write_to_file];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)write_to_file
|
- (void)write_to_file
|
||||||
{
|
{
|
||||||
for (int i = 0; i != [settings count]; i ++)
|
for (int i = 0; i != [settings count]; i ++)
|
||||||
@ -207,7 +215,6 @@ static NSMutableDictionary* subpath_setting(config_file_t* config, NSString* nam
|
|||||||
|
|
||||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||||
{
|
{
|
||||||
[self write_to_file];
|
|
||||||
return [settings count];
|
return [settings count];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +228,12 @@ static NSMutableDictionary* subpath_setting(config_file_t* config, NSString* nam
|
|||||||
return [[settings objectAtIndex:section] objectAtIndex:0];
|
return [[settings objectAtIndex:section] objectAtIndex:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)handle_boolean_switch:(UISwitch*)swt
|
||||||
|
{
|
||||||
|
NSDictionary* setting = objc_getAssociatedObject(swt, SETTINGID);
|
||||||
|
[setting setValue: (swt.on ? @"true" : @"false") forKey:@"VALUE"];
|
||||||
|
}
|
||||||
|
|
||||||
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||||
{
|
{
|
||||||
NSMutableDictionary* setting = [[settings objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1];
|
NSMutableDictionary* setting = [[settings objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1];
|
||||||
@ -235,12 +248,18 @@ static NSMutableDictionary* subpath_setting(config_file_t* config, NSString* nam
|
|||||||
if (cell == nil)
|
if (cell == nil)
|
||||||
{
|
{
|
||||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"boolean"];
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"boolean"];
|
||||||
cell.accessoryView = [[UISwitch alloc] init];
|
|
||||||
|
UISwitch* accessory = [[UISwitch alloc] init];
|
||||||
|
[accessory addTarget:self action:@selector(handle_boolean_switch:) forControlEvents:UIControlEventValueChanged];
|
||||||
|
|
||||||
|
cell.accessoryView = accessory;
|
||||||
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
|
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
|
||||||
}
|
}
|
||||||
|
|
||||||
UISwitch* swt = (UISwitch*)cell.accessoryView;
|
UISwitch* swt = (UISwitch*)cell.accessoryView;
|
||||||
swt.on = [[setting valueForKey:@"VALUE"] isEqualToString:@"true"];
|
swt.on = [[setting valueForKey:@"VALUE"] isEqualToString:@"true"];
|
||||||
|
|
||||||
|
objc_setAssociatedObject(swt, SETTINGID, setting, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
}
|
}
|
||||||
else if ([type isEqualToString:@"E"] || [type isEqualToString:@"F"])
|
else if ([type isEqualToString:@"E"] || [type isEqualToString:@"F"])
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user