PageViewController on Xamarin will not load child content - ios

I am quite new to mobile dev so forgive me if some of this seems trivial. But I am trying to get a basic PageViewController working in Xamarin iOS with a number of different sign up controllers I have, for different stages of the app signup. So a user will fill in page one, click continue and be taken to step two and so forth.
I used a sample PageViewController project from GitHub and got that working on my simulator fine. However when I try and use it with my sign up controllers, I get an error
Foundation.MonoTouchException: Objective-C exception thrown. Name:
NSUnknownKeyException Reason: [
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key DateOfBirthText.
This is the parent view controller OnLoad method
public override void ViewDidLoad()
{
base.ViewDidLoad();
_pageViewController = Storyboard.InstantiateViewController("SignInPageViewController") as UIPageViewController;
_pageViewController.DataSource = new PageViewControllerDataSource(this, _userInput);
var startVc = ViewControllerAtIndex(0);
var viewControllers = new[] {startVc};
_pageViewController.SetViewControllers(viewControllers, UIPageViewControllerNavigationDirection.Forward, false, null);
_pageViewController.View.Frame = new CGRect(0, 0, View.Frame.Width, View.Frame.Size.Height - 50);
AddChildViewController(_pageViewController);
View.AddSubview(_pageViewController.View);
_pageViewController.DidMoveToParentViewController(this);
}
It throws the error on line
_pageViewController.SetViewControllers
And this is the designer code for the child controller that tries to be loaded into the PageViewController and throws the error
{
[Register ("SigninViewControllerStageOne")]
partial class SigninViewControllerStageOne
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField DateOfBirthText { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField NameText { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIButton NextStepButton { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField PhoneNumberText { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UILabel TitleLabel { get; set; }
void ReleaseDesignerOutlets ()
{
if (DateOfBirthText != null) {
DateOfBirthText.Dispose ();
DateOfBirthText = null;
}
if (NameText != null) {
NameText.Dispose ();
NameText = null;
}
if (NextStepButton != null) {
NextStepButton.Dispose ();
NextStepButton = null;
}
if (PhoneNumberText != null) {
PhoneNumberText.Dispose ();
PhoneNumberText = null;
}
if (TitleLabel != null) {
TitleLabel.Dispose ();
TitleLabel = null;
}
}
}
}
Update: Full stack trace
Unhandled Exception:
Foundation.MonoTouchException: Objective-C exception thrown. Name:
NSUnknownKeyException Reason: [
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key DateOfBirthText.
Native stack trace:
0 CoreFoundation 0x00958494
__exceptionPreprocess + 180
1 libobjc.A.dylib 0x08fd3e02
objc_exception_throw + 50
2 CoreFoundation 0x009580b1 -[NSException
raise] + 17
3 Foundation 0x014777f8
-[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x013d1e6a
_NSSetUsingKeyValueSetter + 115
5 Foundation 0x013d1def
-[NSObject(NSKeyValueCoding) setValue:forKey:] + 295
6 UIKit 0x0397b931 -[UIViewController
setValue:forKey:] + 85
7 Foundation 0x0140654b
-[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 384
8 UIKit 0x03bf8a62
-[UIRuntimeOutletConnection connect] + 132
9 libobjc.A.dylib 0x08fe800c -[NSObject
performSelector:] + 62
10 CoreFoundation 0x00881131 -[NSArray
makeObjectsPerformSelector:] + 273
11 UIKit 0x03bf70fc -[UINib
instantiateWithOwner:options:] + 2102
12 UIKit 0x03983380 -[UIViewController
_loadViewFromNibNamed:bundle:] + 429
13 UIKit 0x03983db8 -[UIViewController
loadView] + 189
14 UIKit 0x039841c4 -[UIViewController
loadViewIfRequired] + 154
15 UIKit 0x03984ab1 -[UIViewController
view] + 35
16 UIKit 0x04038649
-[UIPageViewController _setViewControllers:withCurlOfType:fromLocation:direction:animated:notifyDelegate:completion:]
+ 2250
17 UIKit 0x0403a76a
-[UIPageViewController setViewControllers:direction:animated:completion:] + 309
18 ??? 0x1a6a07cc 0x0 + 443156428
19 ??? 0x1a69f6d0 0x0 + 443152080
20 ??? 0x18d3200f 0x0 + 416489487
21 ??? 0x18d29c1d 0x0 + 416455709
22 BarPandaApp 0x001be859
mono_jit_runtime_invoke + 921
23 BarPandaApp 0x0027d0ce
mono_runtime_invoke + 142
24 BarPandaApp 0x0035e225 xamarin_trampoline
+ 5605
25 UIKit 0x0397fb72 -[UIViewController
_sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
26 UIKit 0x03984692 -[UIViewController
loadViewIfRequired] + 1384
27 UIKit 0x039d02bb
-[UINavigationController _layoutViewController:] + 52
28 UIKit 0x039d0b75
-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 421
29 UIKit 0x039d0d1c
-[UINavigationController _startTransition:fromViewController:toViewController:] + 145
30 UIKit 0x039d2118
-[UINavigationController _startDeferredTransitionIfNeeded:] + 1038
31 UIKit 0x039d339e
-[UINavigationController __viewWillLayoutSubviews] + 68
32 UIKit 0x03bb84b7
-[UILayoutContainerView layoutSubviews] + 252
33 UIKit 0x038843d4
-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 810
34 libobjc.A.dylib 0x08fe8059 -[NSObject
performSelector:withObject:] + 70
35 QuartzCore 0x0b607096 -[CALayer
layoutSublayers] + 144
36 QuartzCore 0x0b5fa8b6
_ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388
37 QuartzCore 0x0b5fa71a
_ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
38 QuartzCore 0x0b5ecee7
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317
39 QuartzCore 0x0b621847
_ZN2CA11Transaction6commitEv + 561
40 QuartzCore 0x0b622108
_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
41 CoreFoundation 0x0086a75e
CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30
42 CoreFoundation 0x0086a6be
__CFRunLoopDoObservers + 398
43 CoreFoundation 0x0085f868
CFRunLoopRunSpecific + 504
44 CoreFoundation 0x0085f65b CFRunLoopRunInMode
+ 123
45 UIKit 0x037ae2da -[UIApplication
_run] + 540
46 UIKit 0x037b3eb9 UIApplicationMain
+ 160
47 ??? 0x18d27144 0x0 + 416444740
48 ??? 0x18d26ef4 0x0 + 416444148
49 ??? 0x18d249a0 0x0 + 416434592
50 ??? 0x18d24620 0x0 + 416433696
51 ??? 0x18d24823 0x0 + 416434211
52 BarPandaApp 0x001be859
mono_jit_runtime_invoke + 921
53 BarPandaApp 0x0027d0ce
mono_runtime_invoke + 142
54 BarPandaApp 0x002822d1
mono_runtime_exec_main + 401
55 BarPandaApp 0x00282095
mono_runtime_run_main + 645
56 BarPandaApp 0x0013a3d5 mono_jit_exec +
213
57 BarPandaApp 0x0036d73a xamarin_main +
2474
58 BarPandaApp 0x0036e351 main + 65
59 libdyld.dylib 0x094ada25 start + 1

Actually, I don't think you should use UIPageViewController to implement the sign up progress.
But if you just need it, there is a sample I wrote for other, you can check this link to get it:
xamarin.ios implement PageController with images only code
I suggest you to use UINavigationController, It can make all you need, there is an example:
This is the code for AppDelegate(override the method "FinishedLaunching"):
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
SignUpStepViewController step1 = new SignUpStepViewController (1, UIColor.Red);
SignUpStepViewController step2 = new SignUpStepViewController (2, UIColor.Green);
SignUpStepViewController step3 = new SignUpStepViewController (3, UIColor.Blue);
step1.SetNextController(step2);
step2.SetNextController(step3);
UINavigationController myNavigationController = new UINavigationController (step1);
this.Window = new UIWindow (UIScreen.MainScreen.Bounds);
this.Window.RootViewController = myNavigationController;
this.Window.MakeKeyAndVisible ();
return true;
}
This is the code for SignUpStepViewController:
public class SignUpStepViewController : UIViewController
{
public SignUpStepViewController (int index,UIColor color)
{
this.Title = "Step " + index;
this.View.BackgroundColor = color;
}
public void SetNextController(SignUpStepViewController nextC)
{
UIBarButtonItem btnContinue = new UIBarButtonItem ("Continue",UIBarButtonItemStyle.Done, delegate {
this.NavigationController.PushViewController(nextC,true);
});
this.NavigationItem.SetRightBarButtonItem (btnContinue,true);
}
}
Hope it can help you.
If you still need help, just leave the message here, I will check latter.

Related

NSUnknownKeyException even though outlets are defined

I have a custom view with a corresponding xib in a framework. In interface builder, I've set the File's Owner and the view itself to the my subclass of UIView (TotalTokenCountView). I've also setup outlets for two labels in the custom view. However, when I use this custom view in an application, I get an NSUnknownKeyException exception.
I've tried setting the outlet vars to public to ensure that they can be connected outside of the framework, but that didn't work either.
Am I missing something here? Is there more setup I need to do for the outlets to connect?
public class TotalTokenCountView: UIView {
#IBOutlet public weak var tokenLabel: UILabel!
#IBOutlet public weak var tokenCountLabel: UILabel!
public override func awakeFromNib() {
tokenCountLabel.textColor = UIColor.deepPurple
tokenLabel.textColor = UIColor.lavenderGrayMedium
}
static func create() -> TotalTokenCountView {
return mybundle.loadNibNamed("TotalTokenCountView", owner: self, options: nil)!.first! as! TotalTokenCountView
}
}
The code that creates the custom view:
public class TotalTokenCountBarButtonItem: UIBarButtonItem {
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
private func commonInit() {
self.customView = TotalTokenCountView.create()
}
}
IB Screenshots:
Exception:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MyFrameworkTarget.TotalTokenCountView 0x104ed9580> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tokenCountLabel.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a0d31e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x000000010550a031 objc_exception_throw + 48
2 CoreFoundation 0x000000010a0d30b9 -[NSException raise] + 9
3 Foundation 0x0000000104f2bb47 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x000000010622fe8a -[UIRuntimeOutletConnection connect] + 109
5 CoreFoundation 0x000000010a075e8d -[NSArray makeObjectsPerformSelector:] + 317
6 UIKit 0x000000010622e834 -[UINib instantiateWithOwner:options:] + 1856
7 MyFrameworkTarget 0x0000000104ed73bf _T012MyFrameworkTarget19TotalTokenCountViewC6createACyFZ + 431
8 MyFrameworkTarget 0x0000000104ed817b _T012MyFrameworkTarget28TotalTokenCountBarButtonItemC10commonInit33_82940FA39F221CEB8A8645FA6323AFBFLLyyF + 43
9 MyFrameworkTarget 0x0000000104ed80bc _T012MyFrameworkTarget28TotalTokenCountBarButtonItemCACSgSo7NSCoderC5coder_tcfc + 124
10 MyFrameworkTarget 0x0000000104ed813f _T012MyFrameworkTarget28TotalTokenCountBarButtonItemCACSgSo7NSCoderC5coder_tcfcTo + 47
11 UIKit 0x000000010622f725 -[UIClassSwapper initWithCoder:] + 246
12 UIKit 0x000000010648188c UINibDecoderDecodeObjectForValue + 704
13 UIKit 0x00000001064815bf -[UINibDecoder decodeObjectForKey:] + 246
14 UIKit 0x000000010671219b -[UINavigationItem initWithCoder:] + 715
15 UIKit 0x000000010648188c UINibDecoderDecodeObjectForValue + 704
16 UIKit 0x00000001064815bf -[UINibDecoder decodeObjectForKey:] + 246
17 UIKit 0x0000000105f44db1 -[UIViewController initWithCoder:] + 407
18 UIKit 0x0000000105fac885 -[UITabBarController initWithCoder:] + 65
19 UIKit 0x000000010648188c UINibDecoderDecodeObjectForValue + 704
20 UIKit 0x0000000106481a2a UINibDecoderDecodeObjectForValue + 1118
21 UIKit 0x00000001064815bf -[UINibDecoder decodeObjectForKey:] + 246
22 UIKit 0x0000000105f451a0 -[UIViewController initWithCoder:] + 1414
23 UIKit 0x0000000105f74dcc -[UINavigationController initWithCoder:] + 65
24 UIKit 0x000000010648188c UINibDecoderDecodeObjectForValue + 704
25 UIKit 0x00000001064815bf -[UINibDecoder decodeObjectForKey:] + 246
26 UIKit 0x000000010622f3f1 -[UIRuntimeConnection initWithCoder:] + 178
27 UIKit 0x000000010648188c UINibDecoderDecodeObjectForValue + 704
28 UIKit 0x0000000106481a2a UINibDecoderDecodeObjectForValue + 1118
29 UIKit 0x00000001064815bf -[UINibDecoder decodeObjectForKey:] + 246
30 UIKit 0x000000010622e5e2 -[UINib instantiateWithOwner:options:] + 1262
31 UIKit 0x00000001066bb406 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 181
32 UIKit 0x0000000105da5862 -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 112
33 UIKit 0x0000000105da5d33 -[UIApplication _loadMainInterfaceFile] + 272
34 UIKit 0x0000000105da44b9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1403
35 UIKit 0x0000000106166f7e __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 866
36 UIKit 0x0000000106539a39 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
37 UIKit 0x0000000106166bba -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236
38 UIKit 0x00000001061673db -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 675
39 UIKit 0x0000000106ad8614 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 299
40 UIKit 0x0000000106ad84ae -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433
41 UIKit 0x00000001067bc75d __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221
42 UIKit 0x00000001069b74b7 _performActionsWithDelayForTransitionContext + 100
43 UIKit 0x00000001067bc627 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 223
44 UIKit 0x00000001065390e0 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
45 UIKit 0x0000000105da2eac -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 515
46 UIKit 0x0000000106375bcb -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
47 FrontBoardServices 0x000000010d5752f3 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 331
48 FrontBoardServices 0x000000010d57dcfa __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 225
49 libdispatch.dylib 0x00000001089c97ec _dispatch_client_callout + 8
50 libdispatch.dylib 0x00000001089cedb8 _dispatch_block_invoke_direct + 592
51 FrontBoardServices 0x000000010d5a9470 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
52 FrontBoardServices 0x000000010d5a912e -[FBSSerialQueue _performNext] + 439
53 FrontBoardServices 0x000000010d5a968e -[FBSSerialQueue _performNextFromRunLoopSource] + 45
54 CoreFoundation 0x000000010a075bb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
55 CoreFoundation 0x000000010a05a4af __CFRunLoopDoSources0 + 271
56 CoreFoundation 0x000000010a059a6f __CFRunLoopRun + 1263
57 CoreFoundation 0x000000010a05930b CFRunLoopRunSpecific + 635
58 GraphicsServices 0x000000010cdc9a73 GSEventRunModal + 62
59 UIKit 0x0000000105da6057 UIApplicationMain + 159
60 PinataApp 0x0000000104be62c7 main + 55
61 libdyld.dylib 0x0000000108a46955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Remove the references (outlets) from File's Owner and add them to TotalTokenCountView.
Not sure if this is causing your problem, but in your call to loadNibNamed, you're passing self as owner. Since you're in a static method, that's a reference to the class type, not an instance.

My app won't run... because of an unchanged AppDelegate?

My app was working perfectly until I added an #IBAction. Now I just get this error:
2017-06-09 07:55:35.285 Press[1594:102051] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key add.'
* First throw call stack:
(
0 CoreFoundation 0x000000010724bb0b exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001044f3141 objc_exception_throw + 48
2 CoreFoundation 0x000000010724ba59 -[NSException raise] + 9
3 Foundation 0x0000000104008e8b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x0000000104b60644 -[UIViewController setValue:forKey:] + 87
5 UIKit 0x0000000104dcd6b9 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001071f1e8d -[NSArray makeObjectsPerformSelector:] + 269
7 UIKit 0x0000000104dcc06f -[UINib instantiateWithOwner:options:] + 1856
8 UIKit 0x0000000104b66c73 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000104b67589 -[UIViewController loadView] + 177
10 UIKit 0x0000000104b678ba -[UIViewController loadViewIfRequired] + 195
11 UIKit 0x0000000104b6810a -[UIViewController view] + 27
12 UIKit 0x0000000104a3063a -[UIWindow addRootViewControllerViewIfPossible] + 65
13 UIKit 0x0000000104a30d20 -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x0000000104a43b6e -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x00000001049bd31f -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4346
16 UIKit 0x00000001049c3584 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
17 UIKit 0x00000001049c0793 -[UIApplication workspaceDidEndTransaction:] + 182
18 FrontBoardServices 0x000000010895b5f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
19 FrontBoardServices 0x000000010895b46d -[FBSSerialQueue _performNext] + 186
20 FrontBoardServices 0x000000010895b7f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x00000001071f1c01 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
22 CoreFoundation 0x00000001071d70cf __CFRunLoopDoSources0 + 527
23 CoreFoundation 0x00000001071d65ff __CFRunLoopRun + 911
24 CoreFoundation 0x00000001071d6016 CFRunLoopRunSpecific + 406
25 UIKit 0x00000001049bf02f -[UIApplication _run] + 468
26 UIKit 0x00000001049c50d4 UIApplicationMain + 159
27 Press 0x0000000103f1a877 main + 55
28 libdyld.dylib 0x00000001081eb65d start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
This is my Viewcontroller code:
import UIKit
class ViewController: UIViewController {
// OUTLETS
#IBOutlet weak var score: UILabel!
#IBAction func add(_ sender: Any) {
add()
}
// VARIABLES
var scoreVar = 0
let levelUpAt = [50, 100, 500, 1000, 5000, 10000, 50000, 100000]
var currentLevel = 1
var toAdd = 1
// OVERRIDES
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
// FUNCTIONS
// Below code adds to the score
func add() {
scoreVar += 1 // Adds 1 to scoreVar
score.text = "scoreVar"; // Updates text to match
checkForLevelUp(); // Calls the function defined in the next few days ago
}
// Below code checks if the score meets the next level requirements
func checkForLevelUp() {
if (scoreVar - 1 < levelUpAt[currentLevel - 1]) { // Complicated math-y if statment
currentLevel += 1
toAdd += 1
}
}
}
It seems to be stuck on the class AppDelegate: UIResponder, UIApplicationDelegate { line on the AppDelegate, according to the debugger.
Go to your story board and click on the ViewController. Click one the Add button you created.
On the right side in the Outlet Inspector, remove anything mentioning the "Add" button.
Finally, recreate the outlets by option dragging from the button to your view controller and setting the type to "Action".

Application crashes when move from main view controller to another view controller, asks call a stack [duplicate]

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
import UIKit
class SignUpViewController: UIViewController
{
#IBOutlet weak var usernametext: UITextField!
#IBOutlet weak var emailtext: UITextField!
#IBOutlet weak var passwordtext: UITextField!
#IBOutlet weak var retypepasswordtext: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.h
}
#IBAction func Signupbutton(sender: AnyObject) {
let username = usernametext.text ;
let useremail = emailtext.text ;
let password = passwordtext.text ;
let retypepassword = retypepasswordtext.text ;
//alert message with confirmation
func displayMyAlertMessage(UserMessage :String)
{
var myalert=UIAlertController(title:"Alert", message:UserMessage,preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "ok", style:UIAlertActionStyle.Default , handler: nil)
myalert.addAction(okAction)
self.presentViewController(myalert, animated: true, completion: nil)
}
//check empty fields
if(username.isEmpty || useremail.isEmpty || password.isEmpty || retypepassword.isEmpty)
{
//display alert message
displayMyAlertMessage("all fields are reqiured");
return;
}
//password match
if(password != retypepassword)
{
//display alert message
displayMyAlertMessage("passwords do not match");
return;
}
//store data
NSUserDefaults.standardUserDefaults().setObject(username, forKey: "username")
NSUserDefaults.standardUserDefaults().setObject(useremail, forKey: "email")
NSUserDefaults.standardUserDefaults().setObject(password, forKey: "password")
NSUserDefaults.standardUserDefaults().setObject(retypepassword, forKey: "retypepassword")
//alert msg
}
}
error shown:-
2015-06-08 13:24:18.163 login excersice[3506:334174] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<login_excersice.SignUpViewController 0x7be6e4e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key email.'
*** First throw call stack:
(
0 CoreFoundation 0x00293946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01c6fa97 objc_exception_throw + 44
2 CoreFoundation 0x00293561 -[NSException raise] + 17
3 Foundation 0x0071a10e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x00676138 _NSSetUsingKeyValueSetter + 115
5 Foundation 0x006760bd -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x006ab9a6 -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 386
7 UIKit 0x00ddc649 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x01c85724 -[NSObject performSelector:] + 62
9 CoreFoundation 0x001cd5dc -[NSArray makeObjectsPerformSelector:] + 316
10 UIKit 0x00ddb10a -[UINib instantiateWithOwner:options:] + 1775
11 UIKit 0x00bfd624 -[UIViewController _loadViewFromNibNamed:bundle:] + 270
12 UIKit 0x00bfddbb -[UIViewController loadView] + 295
13 UIKit 0x00bfdfef -[UIViewController loadViewIfRequired] + 78
14 UIKit 0x00bfe595 -[UIViewController view] + 35
15 UIKit 0x01271707 -[_UIFullscreenPresentationController _setPresentedViewController:] + 75
16 UIKit 0x00bd3a81 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 113
17 UIKit 0x00c0ba61 -[UIViewController _presentViewController:withAnimationController:completion:] + 2102
18 UIKit 0x00c0e5d2 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 345
19 UIKit 0x00c0e424 -[UIViewController presentViewController:animated:completion:] + 224
20 UIKit 0x00c130be -[UIViewController _showViewController:withAction:sender:] + 213
21 UIKit 0x00e4f3b5 -[UIStoryboardShowSegue perform] + 143
22 UIKit 0x010c3b49 -[UIStoryboardSegueTemplate _perform:] + 217
23 UIKit 0x010c3bc5 -[UIStoryboardSegueTemplate perform:] + 116
24 libobjc.A.dylib 0x01c857cd -[NSObject performSelector:withObject:withObject:] + 84
25 UIKit 0x00aa823d -[UIApplication sendAction:to:from:forEvent:] + 99
26 UIKit 0x00aa81cf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
27 UIKit 0x00bdbe86 -[UIControl sendAction:to:forEvent:] + 69
28 UIKit 0x00bdc2a3 -[UIControl _sendActionsForEvents:withEvent:] + 598
29 UIKit 0x00bdb50d -[UIControl touchesEnded:withEvent:] + 660
30 UIKit 0x00af860a -[UIWindow _sendTouchesForEvent:] + 874
31 UIKit 0x00af90e5 -[UIWindow sendEvent:] + 791
32 UIKit 0x00abe549 -[UIApplication sendEvent:] + 242
33 UIKit 0x00ace37e _UIApplicationHandleEventFromQueueEvent + 20690
34 UIKit 0x00aa2b19 _UIApplicationHandleEventQueue + 2206
35 CoreFoundation 0x001b71df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
36 CoreFoundation 0x001acced __CFRunLoopDoSources0 + 253
37 CoreFoundation 0x001ac248 __CFRunLoopRun + 952
38 CoreFoundation 0x001abbcb CFRunLoopRunSpecific + 443
39 CoreFoundation 0x001ab9fb CFRunLoopRunInMode + 123
40 GraphicsServices 0x0402724f GSEventRunModal + 192
41 GraphicsServices 0x0402708c GSEventRun + 104
42 UIKit 0x00aa68b6 UIApplicationMain + 1526
43 login excersice 0x000a748e top_level_code + 78
44 login excersice 0x000a74cb main + 43
45 libdyld.dylib 0x023dcac9 start + 1
46 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Write below statement after storing data into NSUserDefaults
NSUserDefaults.standardUserDefaults().synchronize()

[_NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0..1]

I'm using a simulator for iphone 4s(iOS 7.0.3) for my app and I get the following error
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x003085e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x027568b6 objc_exception_throw + 44
2 CoreFoundation 0x002a94e6 -[__NSArrayM objectAtIndex:] + 246
3 Requisitions 0x0015007a -[PasswordLoginController3 _adjustInputPos] + 61
4 Requisitions 0x0015042a -[PasswordLoginController3 keyboardWasShown:] + 312
5 Foundation 0x02428bf9 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
6 CoreFoundation 0x00364524 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
7 CoreFoundation 0x002bc00b _CFXNotificationPost + 2859
8 Foundation 0x02362951 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
9 UIKit 0x009ffb1b -[UIInputViewTransition postNotificationsForTransitionEnd] + 1054
10 UIKit 0x009f6138 __53-[UIPeripheralHost(UIKitInternal) executeTransition:]_block_invoke1332 + 455
11 UIKit 0x006993c0 -[UINavigationControllerKeyboardAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:] + 501
12 UIKit 0x009f5a7c -[UIPeripheralHost(UIKitInternal) executeTransition:] + 1258
13 UIKit 0x009f7c0e -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1029
14 UIKit 0x009f8019 -[UIPeripheralHost(UIKitInternal) setInputViews:animated:] + 72
15 UIKit 0x009f8063 -[UIPeripheralHost(UIKitInternal) setInputViews:] + 67
16 UIKit 0x009ef2fa -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1453
17 UIKit 0x006c969a -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 287
18 UIKit 0x006c8f8b -[UIResponder becomeFirstResponder] + 550
19 UIKit 0x005cc19b -[UIView(Hierarchy) becomeFirstResponder] + 114
20 UIKit 0x00c4ce43 -[UITextField becomeFirstResponder] + 51
21 UIKit 0x005cc1e8 -[UIView(Hierarchy) deferredBecomeFirstResponder] + 67
22 UIKit 0x005cc27c -[UIView(Hierarchy) _promoteSelfOrDescendantToFirstResponderIfNecessary] + 115
23 UIKit 0x005cc53e __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 224
24 UIKit 0x005cc388 -[UIView(Hierarchy) _postMovedFromSuperview:] + 260
25 UIKit 0x005d74c1 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1847
26 UIKit 0x005ca9b1 -[UIView(Hierarchy) addSubview:] + 56
27 UIKit 0x00563848 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 1927
28 UIKit 0x005d13ef +[UIView(Animation) performWithoutAnimation:] + 82
29 UIKit 0x00562c96 -[_UINavigationParallaxTransition animateTransition:] + 1155
30 UIKit 0x0069de4e -[UINavigationController _startCustomTransition:] + 3446
31 UIKit 0x006aa0c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
32 UIKit 0x006aacb9 -[UINavigationController __viewWillLayoutSubviews] + 57
33 UIKit 0x007e4181 -[UILayoutContainerView layoutSubviews] + 213
34 UIKit 0x005da267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
35 libobjc.A.dylib 0x0276881f -[NSObject performSelector:withObject:] + 70
36 QuartzCore 0x022182ea -[CALayer layoutSublayers] + 148
37 QuartzCore 0x0220c0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
38 QuartzCore 0x0220bf40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
39 QuartzCore 0x02173ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
40 QuartzCore 0x02174e71 _ZN2CA11Transaction6commitEv + 393
41 QuartzCore 0x02175544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
42 CoreFoundation 0x002d04ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
43 CoreFoundation 0x002d041f __CFRunLoopDoObservers + 399
44 CoreFoundation 0x002ae344 __CFRunLoopRun + 1076
45 CoreFoundation 0x002adac3 CFRunLoopRunSpecific + 467
46 CoreFoundation 0x002ad8db CFRunLoopRunInMode + 123
47 GraphicsServices 0x03ce39e2 GSEventRunModal + 192
48 GraphicsServices 0x03ce3809 GSEventRun + 104
49 UIKit 0x0056fd3b UIApplicationMain + 1225
50 Requisitions 0x000a712c main + 92
51 libdyld.dylib 0x03036701 start + 1
52 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I tried this thread CRASH: *** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 9] and tried to debug at certain breakpoint, but no avail. I couldn't figure out where the issue is happening. Objective C is not my forte , but still fixing this issue.
Method _adjustInputPos
-(void) _adjustInputPos
{
UITextField *currentField = [inputFields objectAtIndex:currentInputIndex];
CGFloat currentInputHeight = currentField.frame.origin.y;
UIView* v = [self.formView viewWithTag:70];
if(v!=nil) {
currentInputHeight += v.frame.origin.y;
}
UIScrollView* sv = (UIScrollView*)self.view;
CGFloat offset = 0;
if (sv.contentOffset.y>=(currentInputHeight)) {
offset = (sv.frame.size.height-kbHeight)/1.5;
} else if((self.view.frame.size.height-kbHeight-currentInputHeight)<currentField.frame.size.height) {
offset = (sv.frame.size.height-kbHeight)/1.5;
} else {
return;
}
if(sv.contentOffset.y==offset) {
return;
}
CGPoint scrollPoint = CGPointMake(0.0, offset);
[sv setContentOffset:scrollPoint animated:YES];
}
Method keyBoardWasShown
- (void) keyboardWasShown:(NSNotification*)notf
{
if(isHidden) {
return;
}
NSDictionary *info = [notf userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
kbHeight = kbSize.height;
BOOL islandscape = [[ClientAuthenticator getInstance].actionHandler isLandscape];
if(!islandscape && [LSUtility isTablet]) {//ipad portrait,no need.
return;
}
if(islandscape ) {
kbHeight = kbSize.width;
}
if (is30Style) {
[self _adjustInputPos];
} else {
[self _adjustInputPos31];
}
UIScrollView *sv = (UIScrollView*)self.view;
CGSize size = CGSizeMake(sv.frame.size.width, sv.frame.size.height+kbHeight/1.5);
[sv setContentSize:size];
}
Thanks
4294967295 is 0xFFFFFFFF in hex, or -1 as an unsigned int.
Check in [PasswordLoginController3 _adjustInputPos] - it is asking for objectAtIndex with the value -1 (which is out of bounds).
Edit since you added code
UITextField *currentField = [inputFields objectAtIndex:currentInputIndex]
This looks to be the line that the error comes from. What is the type of currentInputIndex and where is it initialised/modified?

App crashes after Monotouch update to 5.2.13

After I have updated monotouch to Version 5.2.13 my App crashes when I touched inside a UIButton.
About my Code: (it's a question of a LoginView):
I have a UIViewController which includes a ScrollView.
For each User the ScrollView provides a UIView (the UserImageView).
This UserImageView contains a UserImage, Username and so on. Over the UserImage lays a UIButton which should catches the Touch-Events to selected a User.
This Button causes the Exception below more precisely the HitTest method from the UIView.
I get the following Stacktrace:
Stacktrace:
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at MF.Stationaer.iPad.Application.Main (string[]) <IL 0x00028, 0x00073>
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Native stacktrace:
0 MFiPad_MD 0x0009061c mono_handle_native_sigsegv + 284
1 MFiPad_MD 0x000059a8 mono_sigsegv_signal_handler + 248
2 libsystem_c.dylib 0x92cd259b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 UIKit 0x0228c741 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 96
5 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
6 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
7 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
8 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
9 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
10 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
11 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
12 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
13 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
14 UIKit 0x022a1157 -[UIScrollView hitTest:withEvent:] + 79
15 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
16 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
17 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
18 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
19 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
20 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
21 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
22 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
23 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
24 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
25 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
26 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
27 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
28 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
29 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
30 UIKit 0x02286dbd +[UIWindow _hitTestToPoint:pathIndex:forEvent:] + 378
31 UIKit 0x02258ca0 _UIApplicationHandleEvent + 1648
32 GraphicsServices 0x047c5ef5 PurpleEventCallback + 1274
33 CoreFoundation 0x011a9195 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
34 CoreFoundation 0x0110dff2 __CFRunLoopDoSource1 + 146
35 CoreFoundation 0x0110c8da __CFRunLoopRun + 2218
36 CoreFoundation 0x0110bd84 CFRunLoopRunSpecific + 212
37 CoreFoundation 0x0110bc9b CFRunLoopRunInMode + 123
38 GraphicsServices 0x047c47d8 GSEventRunModal + 190
39 GraphicsServices 0x047c488a GSEventRun + 103
40 UIKit 0x02258626 UIApplicationMain + 1163
41 ??? 0x0b96e514 0x0 + 194438420
42 ??? 0x0b96d6c0 0x0 + 194434752
43 ??? 0x0b96d33c 0x0 + 194433852
44 ??? 0x0b96d42f 0x0 + 194434095
45 MFiPad_MD 0x00009d12 mono_jit_runtime_invoke + 722
46 MFiPad_MD 0x00169e4e mono_runtime_invoke + 126
47 MFiPad_MD 0x0016df34 mono_runtime_exec_main + 420
48 MFiPad_MD 0x001732e5 mono_runtime_run_main + 725
49 MFiPad_MD 0x00066f15 mono_jit_exec + 149
50 MFiPad_MD 0x002115d5 main + 2837
51 MFiPad_MD 0x00002d65 start + 53
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Here is the important Part of my Code:
public class LoginViewController : UIViewController
{
...
public override void ViewDidLoad()
{
...
BuildUserUI();
...
}
private void BuildUserUI()
{
currentIconLocation = new PointF(50, 10);
for (var i = 0; i < UserList.List.Count; i++)
CreateUserInGrid(UserList.GetUserByIndex(i));
}
private void CreateUserInGrid(LoginUser user)
{
var imgFrame = new RectangleF(currentIconLocation.X, currentIconLocation.Y, 140, 170);
var loginImg = new UILoginImage(imgFrame);
loginImg.Image = user.Image ?? defaultUserImage.CGImage;
loginImg.Name = user.Nachname;
if (!string.IsNullOrEmpty(user.Vorname))
loginImg.Name += ", " + user.Vorname;
loginImg.Tag = user.UserIndex;
loginImg.AddTarget(this, new Selector("ShowNumberPad:"), UIControlEvent.TouchUpInside);
loginImg.LoginUser = user;
scrollView.AddSubview(loginImg);
loginImages.Add(loginImg);
limitedScrollView.UserInteractionEnabled = false;
var newSize = new SizeF(scrollView.Frame.Size.Width, currentIconLocation.Y + imgFrame.Size.Height + 20);
scrollView.ContentSize = newSize;
limitedScrollView.ContentSize = new SizeF(limitedScrollView.Frame.Size.Width, limitedScrollView.Frame.Size.Height);
currentIconLocation.X += imgFrame.Size.Width;
if (currentIconLocation.X + imgFrame.Size.Width > scrollView.Frame.Size.Width)
{
currentIconLocation.Y += imgFrame.Size.Height;
currentIconLocation.X = 50;
}
}
[Export("ShowNumberPad:")]
private void ShowNumberPad(NSObject sender)
{
...
}
}
public class UILoginImage : UIView
{
[Export("initWithFrame:")]
public UILoginImage(RectangleF frame)
: base(frame)
{
var shadowFrame = new RectangleF(0, 0, 117, 148);
wrapperControl = new UIControl(shadowFrame);
AddSubview(wrapperControl);
shadowImage = new UIImageView(shadowFrame);
shadowImage.Image = ImageCache.GetResourceImage("Images/Login/LoginSchatten.png");
wrapperControl.AddSubview(shadowImage);
var mainBackFrame = new RectangleF(8, 9, 98, 128);
whiteBackgroundImage = new UIImageView(mainBackFrame);
whiteBackgroundImage.Image = ImageCache.GetResourceImage("Images/Login/Singlewhite.png");
wrapperControl.AddSubview(whiteBackgroundImage);
var imageFrame = new RectangleF(13, 15, 87, 116);
clickHelper = UIButton.FromType(UIButtonType.Custom);
clickHelper.Frame = imageFrame;
wrapperControl.AddSubview(clickHelper);
userImage = new UIImageView(imageFrame);
AddSubview(userImage);
var mitarbeiterlabelFrame = new RectangleF(-12, 137, 140, 25);
mitarbeiterNameLabel = new FontSizeLabel(mitarbeiterlabelFrame);
mitarbeiterNameLabel.TextAlignment = UITextAlignment.Center;
mitarbeiterNameLabel.Font = UIFont.SystemFontOfSize(12);
mitarbeiterNameLabel.Opaque = false;
mitarbeiterNameLabel.BackgroundColor = UIColor.Clear;
AddSubview(mitarbeiterNameLabel);
var benutzerlabelFrame = new RectangleF(mitarbeiterlabelFrame.X, mitarbeiterlabelFrame.Y + 13, 140, 25);
benutzerNameLabel = new FontSizeLabel(benutzerlabelFrame);
benutzerNameLabel.TextAlignment = UITextAlignment.Center;
benutzerNameLabel.Font = UIFont.SystemFontOfSize(10);
benutzerNameLabel.Opaque = false;
benutzerNameLabel.BackgroundColor = UIColor.Clear;
benutzerNameLabel.TextColor = UIColor.DarkGray;
AddSubview(benutzerNameLabel);
}
public void AddTarget(NSObject target, Selector action, UIControlEvent controlEvents)
{
clickHelper.AddTarget(target, action, controlEvents);
}
public void RemoveTarget(NSObject target, Selector action, UIControlEvent controlEvents)
{
clickHelper.RemoveTarget(target, action, controlEvents);
}
}
I'm not sure your use of AddTarget is a good way to hook up a UIButton's click.
You should be using clickHelper.TouchUpInside to wire up click events. This is a standard C# event.
Another option would be to wire up an action to this event inside your XIB file in XCode.

Resources