简体   繁体   中英

Meaning of exclamation mark in iOS Designer on Xamarin Studio

I'm working with the iOS Designer and I have a storyboard with different views on it (navigation controller, ...). On nearly each view there is a red exclamation mark on the right side at the bottom. I get errors like

System.NullReferenceException
Object reference not set to an instance of an object

If I go to the corresponding code line:

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()
{
    return TopViewController.GetSupportedInterfaceOrientations();
}

This is part of my CustomNavigationController . If I set the class name on the iOS Designer I get the error. What do I have to add here? The constructor looks like the following:

public CustomNavigationController (IntPtr handle) : base (handle)
{
}

Do I have to instantiate it in the AppDelegate?

On another view controller I get a similar Exception (with a different stack) and it points me to this line:

this.NavigationController.NavigationBar.TintColor = UIColor.FromRGB (21, 66, 139);

The app seems to work fine on simulator and on device though.

How do I resolve this issue?

EDIT:

I now removed the code in my view controller:

this.NavigationController.NavigationBar.TintColor = UIColor.FromRGB (21, 66, 139);

As replacement I moved this code to the Application Delegate FinishedLaunching() :

UINavigationBar.Appearance.TintColor = UIColor.FromRGB (21, 66, 139);

The result is that now I don't have the exclamation mark for this view controller and the color is as desired. But the preview in the iOS Designer doesn't show me the correct color anymore.

If I comment out GetSupportedInterfaceOrientations() in my CustomNavigationController than the other exclamation mark has been removed. I thought I need this function for defining the orientation of each view controller. A quick look showed that it seems to work.

There are restriction on what the design time can support. You should replace any dynamic data, for example data loaded from a service, with dummy data when on design mode. The same applies to runtime objects like TopViewController which is only available at runtime.

if (Site != null && Site.DesignMode)
{
    // use dummy data for designer surface
}
else
{
    // use live data
}

This document explains it in more detail:

http://developer.xamarin.com/guides/ios/user_interface/designer/ios_designable_controls_overview/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM