2012-05-30 4 views
0

iOS5 및 스토리 보드를 사용하고 있습니다. 두 개의 서로 다른 식별자가있는 두 개의보기가 있습니다. 장치의 방향을 변경할 때보기를 변경하고 싶습니다.iOS - 기기 방향이 변경된보기

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
     (interfaceOrientation == UIInterfaceOrientationLandscapeRight))){ 

     self.view = [self.storyboard instantiateViewControllerWithIdentifier:@"Landscape"]; 

    } 
    else if(((interfaceOrientation == UIInterfaceOrientationPortrait) || 
       (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){ 

     self.view = [self.storyboard instantiateViewControllerWithIdentifier:@"Portrait"]; 

    } 

    return YES; 
} 

그러나 응용 프로그램 충돌 : 이 내 코드입니다. 어느 것이 문제입니까?

EDIT : 장치를 회전 할 때 uiview를 두 개 추가하고 두 ID를 uiview에 놓으면 충돌이 발생합니다.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 

} 

- (void) orientationChanged:(id)object 
{ 
    portraitView = [self.storyboard instantiateViewControllerWithIdentifier:@"TermoregolatoreTop"]; 
    landscapeView = [self.storyboard instantiateViewControllerWithIdentifier:@"Landscape"]; 

    UIInterfaceOrientation interfaceOrientation = [[object object] orientation]; 

    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 

     self.view = self.portraitView; 
    } 
    else 
    { 

     self.view = self.landscapeView; 
    } 
} 

답변

0
self.view = [self.storyboard instantiateViewControllerWithIdentifier:@"Portrait"]; 

idUIViewController A를 반환합니다 그리고 당신은 UIView에 할당됩니다 이 코드입니다.

+0

좋아, 만약 내가 uiview 두 추가하고 나는이 장치에 응용 프로그램 충돌 회전이 두 ID를 할당합니다. 수정 사항을 확인하십시오. – Kerberos

+0

충돌은 무엇을 말합니까? *** 먼저 던져 호출 스택 : – Peres

+0

인식 할 수없는 선택은 예를 0x745bbe0 – Kerberos

0

보기 컨트롤러를 해제 할 때 UIDeviceOrientationDidChangeNotification에있는 관찰자를 제거해야합니다.

메모리에서 제거되었을 가능성이 가장 높은 클래스에서 알림이 트리거되기 때문에 충돌이 발생합니다.