2014-04-23 2 views
0

두 개의 서브 클래 싱 된 CollectionViewFlowLayouts간에 전환하는 데 문제가 있습니다.사용자 정의 CollectionView 레이아웃 - 할당 취소 된 NSDictionary로 메시지가 전송되었습니다.

내 collectionViewController에서 다음 메소드를 호출

헤더 :

@property (nonatomic, strong) PortraitFlowLayout *portraitFlowLayout; 
@property (nonatomic, strong) LandscapeFlowLayout *landscapeFlowLayout; 

구현 :

- (LandscapeFlowLayout *)landscapeFlowLayout 
{ 
    if (_landscapeFlowLayout == nil) { 
     _landscapeFlowLayout = [[LandscapeFlowLayout alloc] init]; 

     self.collectionView.collectionViewLayout = _landscapeFlowLayout; 


    } 
    [self.collectionView.collectionViewLayout invalidateLayout]; 
    return _landscapeFlowLayout; 
} 

- (PortraitFlowLayout *)portraitFlowLayout 
{ 
    if (_portraitFlowLayout == nil) { 
     _portraitFlowLayout = [[PortraitFlowLayout alloc] init]; 

     self.collectionView.collectionViewLayout = _portraitFlowLayout; 


    } 
    [self.collectionView.collectionViewLayout invalidateLayout]; 
    return _portraitFlowLayout; 
} 
:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

    if (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) { 

     self.landscapeFlowLayout = nil; 
     [self portraitFlowLayout]; 
     NSLog(@"Orientation portrait"); 

    } else { 

     self.portraitFlowLayout = nil; 
     [self landscapeFlowLayout]; 
     NSLog(@"Orientation landscape"); 
    } 

    [self.collectionView.collectionViewLayout invalidateLayout]; 

} 

같은 collectionViewController에서 이 viewController 폼을 다른 viewCont 폼으로 밀어 넣기 때문에 두 레이아웃이 모두 유효하다는 것을 알았습니다. 그리고 가로 및 세로 레이아웃 모두를 사용해 보았습니다. 잘 작동합니다.

방향을 변경할 때 문제가 발생합니다. 첫 번째 방향 변경은 괜찮 았고 레이아웃은 예상대로 변경됩니다. 그러나 그때 회전 때 (경우에 따라서는 다시 회전하고 몇 번 충돌하기 전에 등), 내가 악기의 좀비 템플릿을 추적 할 때 나에게 다음과 같은 오류를 제공합니다 :

enter image description here

enter image description here

이 오류를 더 자세히 추적하려면 어떻게해야합니까? 또는 문제를 해결 하시겠습니까? 어떤 도움이라도 대단히 감사합니다. 세로로 회전시킬 때

편집 문제 만 보인다 사전에 덕분에 발생합니다.

크리스

+0

NSLog 값은 무엇입니까? –

+0

무엇? 죄송합니다. 디버깅에 능숙하지 않습니다. - 콘솔의 로그 출력은 none입니다 ... – Chris

+0

하지만 코드에 NSLog가 있습니다! –

답변

2

시도 대신 UIDeviceOrientationDidChangeNotification willRotateToInterfaceOrientation를 사용합니다. 애플의 문서에서

이 라인 :

대체 풍경 인터페이스를 지원하려면 다음을 수행해야합니다

두 개의 뷰 컨트롤러 객체를 구현합니다. 하나는 세로 전용 인터페이스를 제공하고 다른 하나는 가로 전용 인터페이스를 제공합니다. UIDeviceOrientationDidChangeNotification 알림에 등록하십시오. 핸들러 메서드에서 현재 장치 방향을 기준으로 대체보기 컨트롤러를 표시하거나 닫습니다.

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



} 

- (void)orientationChanged:(NSNotification *)notification 
{ 

    //without selector event may be lost 
    [self performSelector:@selector(updateFrameWithOrientation) withObject:nil afterDelay:0]; 

} 

-(void) updateFrameWithOrientation{ 
    UIInterfaceOrientation deviceOrientation = [UIApplication sharedApplication].statusBarOrientation; 

    if (UIDeviceOrientationIsLandscape(deviceOrientation)) 
    { 


    } 
    else if (UIDeviceOrientationIsPortrait(deviceOrientation)) 
    { 


    } 

    [self.collectionView reloadData]; 

} 
+0

저를 @Sergey 문서로 참조 할 수 있습니까? 응답 주셔서 대단히 감사합니다. – Chris

+0

예 : 물론 [link] (https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html) –

+0

고마워요! 나는 이것에 관해 볼 것이다! – Chris

관련 문제