2014-11-21 2 views
0

UIViewController를 스토리 보드에 추가하고 아래 코드에 따라 UIViewController에 액세스하여 푸시했습니다. 하지만 몇 가지 이유로 NULL로 읽혀지고 있습니다. 이 코드는 정상적으로 작동합니다. 나는 그들 모두를 디버깅했다. wcv에 대해 null을 얻었고 acv 값을 얻었다. 내가 스토리 보드 파일의 XML 코드를 확인하면 내가 함께 거기 뷰 컨트롤러를 찾을 수 있습니다 모두가 IDS 을 StoyboardId 및 UIViewController를 스토리 보드에 추가했지만 프로그래밍 방식으로 xamarin에 읽을 수 없습니다.

을 RestorationId 주 :같은 탐색 코드가 다른 곳에 사용할 수 있습니다. 나는 자 마린 - 아이폰 OS (인디 라이센스)를 사용하고

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); 

둘 사이의 차이는 ActivityViewController2BaseControllerWelcomeScreenController2 동안 상속을 상속한다는 것입니다 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

0 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 클래스

에 대한

Code from the Storyboard

스토리 보드 코드

+0

WelcomeScreenController2 클래스와 ActivityViewController2 클래스의 선언을 해당 생성자와 함께 게시 할 수 있습니까? –

+0

예. 확실한. 나는 지금 당장 그것을 할 것이다. –

+0

@DimitrisTavlikos 선언을 추가했습니다. –

답변

1

아무 것도 변경할 필요가 없었습니다. 그냥 솔루션을 청소하고 디버그/실행을 다시하면 저를 위해 효과가있었습니다.

그러나 @Dimitris가 캐스팅에 문제가 될 수 있다고 주석에 적었습니다. 그럼 정확히 내가 왜 새로운 UIViewController와 늙은 것들과 어지럽 혔어, 그리고 정리가 그걸로 해냈어, 그것은 정리 후 날짜까지 잘 실행됩니까?

관련 문제