I’m trying to implement an UIAlertController customization to show a switch control for one of the actions as described at https://medium.com/@maximbilan/ios-uialertcontroller-customization-5cfd88140db8#.3xe001k06
My Java class for SwitchAlertActionViewController look like this.
I am not completely sure what annotations (if any) I need to add there and also not sure what commented out swift line below would correspond to in the Java code.
public class SwitchAlertActionViewController extends UIViewController {
// @IBOutlet weak var valueSwitch: UISwitch!
UISwitch valueSwitch;
boolean isSwitchOn = false;
public static native SwitchAlertActionViewController alloc();
@Override
public native SwitchAlertActionViewController init();
protected SwitchAlertActionViewController(Pointer peer) {
super(peer);
}
public void viewDidLoad() {
super.viewDidLoad();
valueSwitch.setOn(isSwitchOn);
}
}
I also copied corresponding xib file from https://github.com/maximbilan/UIAlertController-Customization/tree/master/AlertControllerCustomization/Sources
Now, when I call UIAlertAction.setValueForKey:
UIViewController switchController = SwitchAlertActionViewController.alloc() //
.initWithNibNameBundle("SwitchAlertActionViewController", NSBundle.mainBundle());
UIAlertAction combinedAction = UIAlertAction.actionWithTitleStyleHandler("Combined", UIAlertActionStyle.Default, null);
combinedAction.setValueForKey(switchController, "contentViewController");
I get the following error.
Could you please advise what am I doing wrong?
2016-12-27 16:06:59.417 MyApp[74409:6637335] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SwitchAlertActionViewController 0x7bcf2350> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key valueSwitch.'
*** First throw call stack:
(
0 CoreFoundation 0x0794dbf2 __exceptionPreprocess + 194
1 libobjc.A.dylib 0x06e0ce66 objc_exception_throw + 52
2 CoreFoundation 0x0794db21 -[NSException raise] + 17
3 Foundation 0x0449f90d -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 238
4 Foundation 0x043cd476 _NSSetUsingKeyValueSetter + 162
5 Foundation 0x043ccfe8 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
6 UIKit 0x04a43a9e -[UIViewController setValue:forKey:] + 80
7 Foundation 0x043eeb5f -[NSObject(NSKeyValueC
oding) setValue:forKeyPath:] + 309
8 UIKit 0x04cf13ad -[UIRuntimeOutletConnection connect] + 138
9 libobjc.A.dylib 0x06e22177 -[NSObject performSelector:] + 51
10 CoreFoundation 0x078ed180 -[NSArray makeObjectsPerformSelector:] + 272
11 UIKit 0x04cefa6c -[UINib instantiateWithOwner:options:] + 2102
12 UIKit 0x04a4ad23 -[UIViewController _loadViewFromNibNamed:bundle:] + 437
13 UIKit 0x04a4b770 -[UIViewController loadView] + 197
14 UIKit 0x04a4bae9 -[UIViewController loadViewIfRequired] + 188
15 UIKit 0x04a4c50d -[UIViewController view] + 29
16 UIKit 0x04ec66ca -[_UIAlertControllerActionView _loadContentViewControllerView] + 118
17 UIKit 0x04ec7932 -[_UIAlertControllerActionView setAction:] + 847
18 UIKit
0x05479ab3 -[_UIAlertControllerView _actionsChanged] + 668
19 UIKit 0x04c404c8 -[UIAlertController loadView] + 356
20 UIKit 0x04a4bae9 -[UIViewController loadViewIfRequired] + 188
21 UIKit 0x04a4c50d -[UIViewController view] + 29
22 UIKit 0x04a68d3e -[UIViewController _setPresentationController:] + 117
23 UIKit 0x04a5f314 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1528
24 UIKit 0x04a6133c -[UIViewController _presentViewController:withAnimationController:completion:] + 5467
25 UIKit 0x04a64632 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 363
26 UIKit 0x04a6499b -[UIViewController _performCoordina
tedPresentOrDismiss:animated:] + 535
27 UIKit 0x04a64480 -[UIViewController presentViewController:animated:completion:] + 182
28 MOE 0x066471d8 ffi_call_i386 + 24
)
libc++abi.dylib: terminating with uncaught exception of type NSException