2014-11-21 65 views
0

我向故事板添加了一个UIViewController,并试图访问它,并按照下面的代码将它展示出来。但由于某些原因,它被读为NULL。 虽然此代码工作正常。我调试了他们两个,我得到空为wcv并得到acv的值,是的。如果我检查故事板文件的XML代码,我可以找到视图控制器有两个是IDS StoyboardIdRestorationId添加了一个UIViewController到故事板,但无法在xamarin中以编程方式读取它ios

注:相同的导航代码工作其他地方。我使用Xamarin-IOS(独立许可证)

WelcomeScreenController2 wcv =(UIApplication.SharedApplication.Delegate as AppDelegate).StoryBoard.InstantiateViewController ("WelcomeScreenController2") as WelcomeScreenController2; 
             this.NavigationController.PushViewController(wcv,true); 




ActivityViewController2 acv = (UIApplication.SharedApplication.Delegate as AppDelegate).StoryBoard.InstantiateViewController ("ActivityViewController2") as ActivityViewController2; 
             this.NavigationController.PushViewController (acv, true); 

两者之间的区别是ActivityViewController2继承BaseControllerWelcomeScreenController2继承UIViewController

BaseController代码

public partial class BaseController : UIViewController 
    { 
     // provide access to the sidebar controller to all inheriting controllers 
     protected SidebarController SidebarController { 
      get { 
       return (UIApplication.SharedApplication.Delegate as AppDelegate).RootViewController.SidebarController; 
      } 
     } 

     // provide access to the sidebar controller to all inheriting controllers 
     protected NavController NavController { 
      get { 
       return (UIApplication.SharedApplication.Delegate as AppDelegate).RootViewController.NavController; 
      } 
     } 

     public BaseController (IntPtr handle) : base (handle) 
     { 
     } 
     public BaseController(string nibName, NSBundle bundle) : base(nibName, bundle) 
     { 
     } 



     public override void ViewDidLoad() 
     { 
      base.ViewDidLoad(); 

      NavigationItem.SetLeftBarButtonItem(
       new UIBarButtonItem(UIImage.FromBundle("menu-icon") 
        , UIBarButtonItemStyle.Plain 
        , (sender,args) => { 
         SidebarController.ToggleMenu(); 
        }), true); 
     } 

     public override void ViewWillAppear (bool animated) 
     { 
      base.ViewWillAppear (animated); 

     } 

     public override void ViewDidAppear (bool animated) 
     { 
      base.ViewDidAppear (animated); 
     } 

     public override void ViewWillDisappear (bool animated) 
     { 
      base.ViewWillDisappear (animated); 
     } 

     public override void ViewDidDisappear (bool animated) 
     { 
      base.ViewDidDisappear (animated); 
     } 

    } 

StoryBoardCode SS

Code from the Storyboard

故事板代码为WelcomeScreenController2

<scene sceneID="684"> 
      <objects> 
       <viewController id="685" sceneMemberID="viewController" customClass="WelcomeScreenController2" storyboardIdentifier="WelcomeScreenController2" restorationIdentifier="WelcomeScreenController2"> 
        <view key="view" contentMode="scaleToFill" id="686"> 
         <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> 
         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> 
         <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> 
        </view> 
       </viewController> 
       <placeholder placeholderIdentifier="IBFirstResponder" id="687" userLabel="First Responder" sceneMemberID="firstResponder"/> 
      </objects> 
      <point key="canvasLocation" x="4000" y="135"/> 
     </scene> 

WelcomeScreen2类

public partial class WelcomeScreenController2 : UIViewController 
    { 
     public WelcomeScreenController2 (IntPtr handle) : base (handle) 
     { 
     } 
} 

ActivityViewController2类

public partial class ActivityViewController2 : BaseController 
    { 
public ActivityViewController2 (IntPtr handle) : base (handle) 
     { 
      Title = "ACTIVITY"; 
     } 

     public ActivityViewController2() : base ((string)null, null) 
     { 
      Title = "ACTIVITY"; 
     } 
} 
+0

请问您可以发布WelcomeScreenController2和ActivityViewController2类的声明以及它们的构造函数吗? – 2014-11-21 10:51:48

+0

是的。当然。我现在会这样做。 – 2014-11-21 10:53:39

+0

@DimitrisTavlikos添加了声明。 – 2014-11-21 11:00:38

回答

1

它并不要求我改变任何东西。刚刚清理解决方案和调试/运行再次,这对我工作。

但是@Dimitris在评论中写道,这可能是一个铸造问题。那么为什么我确切地说它是一个新的UIViewController而不是旧的,以及清理与它有什么关系,它在清理之后运行良好,直到日期?

相关问题