0

테이블과 세부보기 컨트롤러 인 마스터 viewcontroller가있는 UISplitViewController가 있습니다.세부 정보 변경 마스터보기 컨트롤러 항목의 컨트롤러보기 UISplitViewController

나는 그래서 그것을 구현 : -

MainViewController.cs

public override void ViewDidLoad() 
    { 
     UpdateView(masterVC,detailVC); 
    } 
    public void UpdateView(UIViewController master, UIViewController detail) 
    { 
     this.ViewControllers = new ViewControllers[]{master, detail}; 
    } 

이 잘 작동합니다. 이제 사용자가 마스터 viewcontroller에서 행을 클릭 할 때 디테일 뷰 컨트롤러를 다른 뷰 컨트롤러로 변경하려고합니다.

은 내가 할 것은 : -이 아무것도하지 않고 새에 대한 상세보기를 변경하지 않습니다

public override void RowSelected(UITableView tableView, NSIndexPath indexPath) 
    { 
      var mainVC = StoryBoard.InstantiateViewController("Main_VC") as MainViewController; 
      mainVC.UpdateView(mainVC.ViewControllers[0], newDetailVc); 
    } 

. 어떻게 구현할 수 있습니까?

답변

0

응용 프로그램이 시작될 때로드 한 원본에 대한 포인터를 제공하지 않고 마스터보기 컨트롤러를 다시 인스턴스화하는 경우 '마스터'보기 컨트롤러의 상세보기 만 업데이트하면됩니다 그것은 단지 기억 속에 자리 잡고 있습니다.

당신이 MainViewController ViewDidAppear 방법에서 응용 프로그램을 실행

은과 같이 자체에 정적 참조를 만들 :

public override void RowSelected(UITableView tableView, NSIndexPath indexPath) 
{ 
     var mainVC = StoryBoard.InstantiateViewController("Main_VC") as MainViewController; 
     mainVC.MVCPointer.UpdateView(mainVC.MVCPointer, newDetailVc); 
} 

이 훨씬 정돈이 있습니다

public static MainViewController MVCPointer {get; private set;} 

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

    MVCPointer = (self as MainViewController). 
} 

그런 다음 rowselected에서 다음 작업을 수행 할 것 위의 방법은 현재 코드를 적용하는 빠른 방법 일 뿐이므로 개인적으로 AppDelegate 내부의 정적 변수 안에 모든 탐색 컨트롤러에 대한 참조를 저장하므로 어디서나 액세스 할 수 있습니다. 다른 뷰 컨트롤러 및 탐색 컨트롤러가 많은 응용 프로그램이 있어야합니다. 에 대한

private static MainViewController MVCMain {get ; private set} 

public void nameofyourtableviewsource (object tableviewdata, MainViewController cont) 
{ 
     MVCMain = cont; 
} 

public override void RowSelected(UITableView tableView, NSIndexPath indexPath) 
{ 
     (mainVC.ViewControllers[0] as MainViewController).UpdateView(mainVC, newDetailVc); 
} 
+0

감사 :

당신이 원하는 일을 다른 방법은 (당신이 하나를 사용하는 경우) tableviewsource 클래스에

당신이 간단 할 일을 할 수있는 그런 식으로 당신의 mainviewcontroller의 참조를 전달하는 것입니다 댓글. 첫 번째 솔루션에서 MVCPointer는 무엇입니까? – user3034944

+0

미안하지만 completley는 그것을 클래스에 할당하는 것에 대해 글을 썼습니다. 위의 코드 스 니펫을 수정 했으므로 이제는 이해해야합니다. – Digitalsa1nt

+0

첫 번째 방법을 시도했지만 코드와 동일한 방식으로 작동합니다. 세부 컨트롤러가 변경되지 않음 – user3034944