2013-05-30 2 views
0

NSViewController가 첨부 된 다른 xib 파일이 있습니다. (아래 스크린 샷) 단추가 StartMenuViewController라는 XIB 파일의목표 c : 버튼 클릭으로 NSView를 전환하는 방법

enter image description here

하나. 해당 버튼을 클릭하고 DetectingUSBViewController로보기를 변경하고 싶습니다. (아래 스크린 샷) 해당 버튼의 IBAction은 StartMenuViewController.m 파일에 있습니다.

enter image description here

그리고 난 내 주요 XIB보기를 제어 할 수 AppController.m를 사용합니다. (NSWindow 표시 + NSView의) (아래 스크린 샷) enter image description here

응용 프로그램이 실행, 나는하여 StartMenuViewController 주먹을 초기화하려고 내 AppController.m 파일에서 다음 일을한다.

-(void)awakeFromNib{ 
      [self initialize]; 
    } 

    -(void) initialize 
    { 
      @autoreleasepool { 
      //mainViewController is a NSViewController and _mainView is a NSView which connect with Custom View in main xib 
       self.mainViewController = [[[StartMenuViewController alloc]initWithNibName:StartMenuView bundle:nil]autorelease]; 
     [_mainView addSubview:[_mainViewController view]]; 
     } 
    } 

그것은 잘 작동하고 처음에는 창에서 StartMenuViewController.xib를 표시합니다,하지만 난 버튼을 클릭 한 후보기를 변경하는 방법을 모른다 (USB 드라이브 찾기). DetectingUSBViewController.xib에 대한 현재보기 변경 사항을 원합니다. 나는 맥 개발에 새로운 사람이다.

감사합니다.

답변

0

간단한 방법은 가능하면 제대로에 USB 버튼을 연결 한 가정, 다음을 수행하십시오

- (IBAction)usbButton:(UIButton *)sender { 

    DetectingUSBViewController *second = [[DetectingUSBViewController alloc] initWithNibName:@"DetectingUSBView" bundle:nil]; 
    [self presentViewController:second animated:YES completion:nil]; 

} 
+0

은 맥이나 iOS 용이인가 (OSX에서 같은 것이 없기 때문에) 벤처을 제시하지 않아? –

+0

iOS 용입니다. 이것이 Mac에도 적용되는지 확실하지 않습니다. – kgdesouz

+0

presentViewController 메서드가 없으므로 osx에서는 작동하지 않습니다. –

0

부하의 DetectingUSBViewController을 startMenuViewControllerDetectingUSBViewController* v1 = [[ViewCont1 alloc] initWithNibName:@"ViewCont1" bundle:nil]; 지금처럼 추가하거나 당신이 원하는 위치보기 [v1 view]로보기를 교체 추가/교체.

0
  1. 당신은 당신이 (같은 아이폰 OS)는의 ViewController를 사용하는 것입니다 => 하나의 방법은 'DetectingUSBViewController.xib보기'필요한 곳에 IBAction를
  2. 를 보내도록 버튼을 연결해야합니다. NSViewController를 서브 클래스화한 다음 DetectingUSBViewController를 할당하십시오.
  3. 뷰를 추가하십시오.

//button click action 
- (IBAction)usbButton:(UIButton *)sender { 
    //! Retain the VC 
    Self.detectingUSBViewController = [[DetectingUSBViewController alloc] initWithNibName:@"DetectingUSBView" bundle:nil]; 

    //add the view 
    [_mainView addSubview:[_detectingUSBViewController view]]; 

}

+0

_mainView는 StartViewController 클래스가 아닌 AppController 클래스에 있습니다. 여기에서 _mainView를 호출하는 방법은 무엇입니까? 감사합니다 –

+0

Self.view.window –

관련 문제