Permalink
Browse files

IASK button title can be overridden by NSUserDefaults value

very handy for toggle buttons (e.g. Login/Logout)
  • Loading branch information...
1 parent e3a43d5 commit 6948e87f6e3350fdede0f16f7a10de6496f0f6c8 Ortwin Gentz committed Mar 15, 2012
@@ -501,7 +501,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.textLabel.text = specifier.title;
cell.detailTextLabel.text = [specifier.defaultValue description];
} else if ([specifier.type isEqualToString:kIASKButtonSpecifier]) {
- cell.textLabel.text = specifier.title;
+ NSString *value = [self.settingsStore objectForKey:specifier.key];
+ cell.textLabel.text = [value isKindOfClass:[NSString class]] ? [self.settingsReader titleForStringId:value] : specifier.title;
cell.textLabel.textAlignment = UITextAlignmentCenter;
} else {
cell.textLabel.text = specifier.title;
@@ -146,7 +146,7 @@ - (IASKSpecifier*)specifierForKey:(NSString*)key {
- (NSString*)titleForSection:(NSInteger)section {
if ([self _sectionHasHeading:section]) {
NSDictionary *dict = [[[self dataSource] objectAtIndex:section] objectAtIndex:kIASKSectionHeaderIndex];
- return [_bundle localizedStringForKey:[dict objectForKey:kIASKTitle] value:[dict objectForKey:kIASKTitle] table:self.localizationTable];
+ return [self titleForStringId:[dict objectForKey:kIASKTitle]];
}
return nil;
}
@@ -161,7 +161,7 @@ - (NSString*)keyForSection:(NSInteger)section {
- (NSString*)footerTextForSection:(NSInteger)section {
if ([self _sectionHasHeading:section]) {
NSDictionary *dict = [[[self dataSource] objectAtIndex:section] objectAtIndex:kIASKSectionHeaderIndex];
- return [_bundle localizedStringForKey:[dict objectForKey:kIASKFooterText] value:[dict objectForKey:kIASKFooterText] table:self.localizationTable];
+ return [self titleForStringId:[dict objectForKey:kIASKFooterText]];
}
return nil;
}
@@ -152,8 +152,8 @@ - (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTapp
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Demo Action 1 called" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
[alert show];
} else {
- UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Demo Action 2 called" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
- [alert show];
+ NSString *newTitle = [[[NSUserDefaults standardUserDefaults] objectForKey:key] isEqualToString:@"Logout"] ? @"Login" : @"Logout";
+ [[NSUserDefaults standardUserDefaults] setObject:newTitle forKey:key];
}
}
@@ -214,7 +214,7 @@
<key>Key</key>
<string>ButtonDemoAction2</string>
<key>Title</key>
- <string>Button Action 2</string>
+ <string>Login</string>
<key>Type</key>
<string>IASKButtonSpecifier</string>
</dict>
@@ -214,7 +214,7 @@
<key>Key</key>
<string>ButtonDemoAction2</string>
<key>Title</key>
- <string>Button Action 2</string>
+ <string>Login</string>
<key>Type</key>
<string>IASKButtonSpecifier</string>
</dict>
View
@@ -73,7 +73,7 @@ InAppSettingsKit adds a `IASKButtonSpecifier` element that allows to call a cust
- (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForKey:(NSString*)key:
-The sender is always an instance of `IASKAppSettingsViewController`, a `UIViewController` subclass. So you can access its view property (might be handy to display an action sheet) or push another view controller. The key corresponds to the `Key` attribute in the Settings plist (useful if you wanna call the same method for different keys). See the sample app for details. 

+The sender is always an instance of `IASKAppSettingsViewController`, a `UIViewController` subclass. So you can access its view property (might be handy to display an action sheet) or push another view controller. The key corresponds to the `Key` attribute in the Settings plist (useful if you wanna call the same method for different keys). Another nifty feature is that the title of IASK buttons can be overriden by the (localizable) value from `NSUserDefaults` (or any other settings store - see below). This comes in handy for toggle buttons (e.g. Login/Logout). See the sample app for details. 

FooterText
----------

0 comments on commit 6948e87

Please sign in to comment.