Bug 19338 - UIStoryboard InstantiateViewController casts views differently between simulator/device
Summary: UIStoryboard InstantiateViewController casts views differently between simula...
Status: RESOLVED UPSTREAM
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 7.1.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL: https://github.com/christoofar/philad...
Depends on:
Blocks:
 
Reported: 2014-04-28 08:53 UTC by Christopher Sawyer
Modified: 2014-04-28 13:04 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED UPSTREAM

Description Christopher Sawyer 2014-04-28 08:53:09 UTC
GitHub location of my project:
https://github.com/christoofar/philadelinquency-mobile-ios


In the simulator this casts correctly:
vc = (PropertyDetailViewController)myStoryboard.InstantiateViewController ("PropertyDetailViewController");

But in the device, it does not:
vc = (PropertyDetailViewController)myStoryboard.InstantiateViewController ("PropertyDetailViewController");
                   ^----  Invalid cast exception (type is UIViewController)


InstantiateViewController() returns NSObject, which should be castable to what the thing is.


Changing the code to step through the cast up from NSObject works, but then fails when I ask the NavigationController to push the view up on the device, but this works fine in the simulator:
	NSObject obj = myStoryboard.InstantiateViewController ("PropertyDetailViewController");
	UIViewController viewc = (UIViewController)obj;
	controller.NavigationController.PushViewController (viewc, true);
                                                            ^-- cannot cast from source type to destination type.

Stack trace:
  at (wrapper castclass) object:__castclass_with_cache (object,intptr,intptr)
  at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject[UINavigationController] (IntPtr ptr, System.Type type, MissingCtorResolution missingCtorResolution) [0x00000] in <filename unknown>:0 
  at MonoTouch.ObjCRuntime.Runtime.GetNSObject[UINavigationController] (IntPtr ptr) [0x00000] in <filename unknown>:0 
  at MonoTouch.UIKit.UIViewController.get_NavigationController () [0x00030] in /Developer/MonoTouch/Source/monotouch/src/build/compat/UIKit/.pmcs-compat.UIViewController.g.cs:1595 
  at PHLpropIPhone.SearchViewController+TableSource.RowSelected (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00020] in /Users/christoofar/Projects/PHLpropMobile/PHLpropIPhone/SearchViewController.cs:134 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pmcs-compat.UIApplication.cs:38 
  at PHLpropIPhone.Application.Main (System.String[] args) [0x00008] in /Users/christoofar/Projects/PHLpropMobile/PHLpropIPhone/Main.cs:16
Comment 1 Christopher Sawyer 2014-04-28 08:54:16 UTC
Test data that can be used in search app that returns data:  1234 MARKET
Comment 2 Rolf Bjarne Kvinge [MSFT] 2014-04-28 09:35:18 UTC
This works fine for me using Xamarin.iOS 7.2.1 - can you please try the beta channel (where Xamarin.iOS 7.2.1 is currently available) and see if it works for you as well?
Comment 3 Christopher Sawyer 2014-04-28 13:04:08 UTC
Hello Rolf

Yes when I switch to the Beta channel it seems to work fine.  I'm guessing this is a manefestation of some previous bug somewhere or other changeset that made it in during Beta.   I'll stick to developing against Beta for now and switch back to Release when the next cycle is done.

Thank you so much for helping me test this. I'm marking this closed.