Xamarin iOS. InvalidCastException during navigation - ios

I have a problem with the navigation of my iOS app developed using Xamarin.
On any single view in my app, when I used at least one time the back button and popped a view controller, I may have to deal with this System.InvalidCastException on my main class :
Unable to cast object of type 'App.iOS.UI.PhotoTaker.PhotoTakerViewController' (Objective-C type: 'WorkZoneSelectorViewController') to type 'App.iOS.UI.WorkZoneSelector.WorkZoneSelectorViewController'.
Additional information:
Selector: viewDidLoad
Method: App.iOS.UI.WorkZoneSelector.WorkZoneSelectorViewController:ViewDidLoad ()
In this example, I was on a PhotoTakerViewController and used a PopToRootViewController to go back succesfully to the HomeViewController (this can also happen when I use the "back" button until I'm back on the HomeViewController). Then I tried to use a segWorkZoneSelector to display a WorkZoneViewController. This is where this error appeared. So, for a reason I don't understand, the app try to cast the last view controller I have loaded to the view controller I want to display right now. PhotoTakerViewController and WorkZone inherits from a common AppViewController. None of these 3 classes have an ExportAttribute
I'm not able to reproduce this error systematically.
Something odd with this error message is also the fact that it says that the app crashed on the method WorkZoneSelectorViewController:ViewDidLoad. But when I try to add some instructions at the beginning of the method, these are never called.

Related

how to navigate from one viewcontroller to second viewcontroller in xamarin ios?

Failed to marshal the Objective-C object 0x7a71ed40 (type: SecondViewController). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'NavigationApp.SecondViewController' does not have a constructor that takes one IntPtr argument).
I have a ViewController and secondViewController, When I hookup storyboard to secondViewController, the above error is shown. But without hookup with secondViewController, its working fine.
If you are waiting for some answer to your problem you might want to format it correctly and respect your readers.
You are literally throwing your error message to our face.
Have you tried to follow this guide ? https://developer.xamarin.com/guides/ios/application_fundamentals/ios_code_only/

Swift IOS app won't start after idle for over 1 day

I have a simple app in Swift with just a few views:
A UIWebView
some TableViews
and another view with some data I download from my server
It all works well until when using the app I press the home button, leave there for a while then the iPad goes on sleep mode. A few days later I tap on the app icon and it won't start:
first tap on the icon will select the icon (goes a little darker) and deselect it a few seconds later
second tap will launch the LaunchScreen and crash a few seconds later
double tap the home button and quit the app will sometimes work
I'm just wondering if there is something I need to set on my code to handle idle/long periods of inactivity in something like viewWillDisappear or other methods?
If so I already have this in all my controllers:
override func viewWillDisappear(animated: Bool) {
timer.invalidate()
webView.removeFromSuperview()
}
Maybe I need to call super. in there too? or something else I'm missing?
You should definitely call super in your viewWillDisappear(animated:) method. See UIViewController Class Reference documentation. Also you might want to confirm why you are removing your webView from the view controller's hierarchy.
Discussion
This method is called in response to a view being removed
from a view hierarchy. This method is called before the view is
actually removed and before any animations are configured.
Subclasses can override this method and use it to commit editing
changes, resign the first responder status of the view, or perform
other relevant tasks. For example, you might use this method to revert
changes to the orientation or style of the status bar that were made
in the viewDidDisappear: method when the view was first presented. If
you override this method, you must call super at some point in your
implementation.
You probably have some null pointer exception and crash. Maybe you are calling some variable that is not set (and checked if not null).
Try disabling app funcionality (like downloading, storing and using data from server) and see where you app starts working normal again and then procede from there.
Sorry for vague answer but withouth code and maybe some log it is really hard to give specific answer.
And NO, you dont have to do anything special to handle idle/long periods of inactivity.

reloadRootControllersWithNames:contexts: does not load new InterfaceControllers

I have my WatchKit app (WatchOS1) set up in the following way (names have been changed to be project unspecific):
InitialInterfaceController - The main entry point of the watch app. This controller is only used to load several instances (using the same identifier repeatedly in the NSArray) of the next view using reloadRootControllersWithNames:contexts: (called from awakeWithContext:).
FirstInterfaceController - This Interface controller should be what is first displayed for the pages.
However this does not work - I get left with the blank InitialInterfaceController screen. If however I call [self presentControllerWithNames:contexts:] it works as expected, but includes the cancel button, which is not what I want.
I have seen people suggesting to use this method to dynamically create multiple page navigation scenes, but I cannot see why this doesn't work. The FirstInterfaceController's awakeWithContext: is never called.
Has anybody had this problem or is there a fix available?
Do you have the right value for the Identity in the interface controller's attribute inspector? (I have seen issues when the identity and class name are the same, make sure they are different)
Is that interface controller added to the right module in the identity inspector?

You are using the component wrong shyNavBarManager

I'm trying to implent shyNavBarManager in my app:
I have a UITableview in storyboard and trying to use shyNavNarManager:
self.shyNavBarManager.scrollView = self.tbPertos;
but I'm getting :
NSInternalInconsistencyException', reason: 'You are using the component wrong... Please see the README file.'
Looking at the documentation:
NSAssert(navbar != nil, #"You are using the component wrong... Please see the README file.");
So it would seem that the navigation bar you are trying to assign here does not exist or is not initialized. See self.tbPertos
The answer isn't to check self.tbPertos, but instead, what is self. It must be a UIViewController subclass, since you are accessing the shyNavBarManager. However, it must be part of a navigation controller before you can start utilizing the component. So, move your code to viewDidLoad or somewhere after the component gets added to a navigation controller.
Note: I developed that library

How to restore UIInputViewController self.view after dismissing the keyboard?

I'm developing an application that has an Keyboard extension, At some uses of the Keyboard extension (for example: when I use the switch keyboard button) the extension is going through the viewDidDisappear and at this case I know I can clean the keyboard and it's getting deallocated with all it's views and the memory is freed. At other uses (for example: when using the Notes application and pressing the Done/Back button) the extension is going through the viewWillDisappear but not through the viewDidDisappear, So in this case I'm not cleaning the Keyboard as it's not reaching my cleaning methods and therefore it's not getting deallocated.
At this point I would expect that when I return to the keyboard by going back to the note for example I would receive the previous UIInputViewController with the view I already built.
Unfortunately at this point the isViewLoaded() method returns false and my UIInputViewController is going again through the loadView method therefore building again all the views all over again, as a result the application memory grows until at some point I reach the nasty didReceiveMemoryWarning method callback.
I would like to restore somehow the view I created for my keyboard in the UIInputViewController that was initialized first. Does some one know is it possible and how could this be achieved?
I was looking into the restorationIdentifier to accomplish this task, correct me if I'm wrong but this is used with an ordinary UIViewController and can't be used with the UIInputViewController as not my AppDelegate is responsible to launch it.
Update
From further research I made, I came to a conclusion that no matter what the operation you commit:
Use Done/Back button in the Notes application.
Switch to the Messages app and use the keyboard there.
Use the “switch keyboard" button
And other scenarios, the UIInputViewController class always goes through the init method.
From my understanding of the object oriented programming this mean that whoever calls my keyboard to reaper does it using the constructor and basically creates a new instance of the keyboard. That means that I will never have an available view on first reappearance of the keyboard in any of the behaviors and I always have to build the keyboard view for the new instance and cleanup the old one. Is this right? or there is a way to presereve the view of the UIInputViewController?
Unless you're using your own custom application with the keyboard to store its previous instance, there's no way to do this. In everything besides a custom application designed by you, it is beyond your scope

Resources