Bug 3887 - Creating a new View (xib) in MD and loading it will cause an exception
Summary: Creating a new View (xib) in MD and loading it will cause an exception
Status: RESOLVED INVALID
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: iOS add-in ()
Version: Trunk
Hardware: Macintosh Mac OS
: High major
Target Milestone: ---
Assignee: Alan McGovern
URL:
Depends on:
Blocks:
 
Reported: 2012-03-13 16:45 UTC by bryan costanich
Modified: 2014-01-30 15:38 UTC (History)
3 users (show)

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


Attachments
repro solution. (3.39 MB, application/zip)
2012-03-13 16:45 UTC, bryan costanich
Details


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 INVALID

Description bryan costanich 2012-03-13 16:45:42 UTC
Created attachment 1513 [details]
repro solution.

If you use the "iPhone View" template in MD to create a new xib file, and then load it in code, e.g.:

public Controller () : base("PortraitView_iPhone", null)

You'll receive an error saying that the nib was loaded but that the view outlet was not set. 

perhaps our view template is broken?

repro project attached. launch and click the third button.
Comment 1 Alan McGovern 2012-03-14 07:40:51 UTC
This is not a bug as such as this is also what Xcode does. The issue here is that when you create a normal View Controller, xcode generates a xib file which connects to the 'view' outlet [0]. This means by default, everything will work for you.

However, if you manually create a class which derives from UIViewController and add a new iPhone or iPad View, this xib file does not connect to the 'view' outlet. i.e. it does not contain the connection in the previous gist. We can 'fix' this by default by generating this connection in the 'iPhone View' and iPad View templates such as this [1].

The other option is that users must be made aware that to make this work they must:
1) Create their controller subclass
2) Add a Register attribute so that it will be made available to obj-c
3) Double click the xib to sync out to xcode
4) Set the 'Custom Class' to the name of the controller you made in your code
5) Create an outlet to connect the 'view' object in your xib to a new outlet called 'view'
6) Save and exit xcode
7) Open the .designer.cs file and delete all references to the 'view' outlet

Some of those steps may be optional, but this is what I did to make bryans solution work correctly. Is there any problem with the solution i proposed in [1]? If not, I will push this to git.

[0] https://gist.github.com/439e5f398e976b847c40
[1] https://gist.github.com/a92346e095e345a997e5
Comment 2 Mikayla Hutchinson [MSFT] 2012-04-17 14:04:13 UTC
Not sure on this one. Adding the connection means we expect the file's owner to have an outlet called View. That might not be true, for example if the user is deserializing a nib directly, in which case they'd have to *remove* the connection.

This is why we have a "view with controller" template.

Also, your comment is wrong. UIViewController already *has* an outlet called view, you should never create a new one.
Comment 3 PJ 2013-11-19 17:04:25 UTC
This bug has been in the NEEDINFO state with no changes for the last 90 days. Can we put this back into the NEW or CONFIRMED state, or are we still awaiting response?

If there is no change in the status of this bug over the next two weeks, this bug will be marked as NORESPONSE.
Comment 4 bryan costanich 2013-11-19 18:18:54 UTC
Not sure why this is in NEEDINFO.
Comment 5 PJ 2013-12-05 18:34:28 UTC
This bug has not been changed from the NEEDINFO state since my previous comment, marking as RESOLVED NORESPONSE.

Please feel free to REOPEN this bug at any time if you are still experiencing the issue. Please add the requested information and set the bug back to the NEW (or CONFIRMED) state.
Comment 6 Jeffrey Stedfast 2014-01-03 13:16:41 UTC
No clue what to do about this except maybe remove stand-alone xib templates?
Comment 7 bryan costanich 2014-01-03 13:25:33 UTC
i think we should do alan's [1] fix.
Comment 8 Jeffrey Stedfast 2014-01-30 15:25:52 UTC
Michael's comment explains why we can't do Alan's suggestion, though.