2012-02-14 187 views
1

我正在加載一個不同的xib時,用戶翻轉到風景,這是工作很好,但我注意到,我的刷卡事件沒有註冊。如何在不丟失UISwipeGestures的情況下調用loadNibNamed?

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if ([self currentlyInLandscapeMode:toInterfaceOrientation]) { 
     [[NSBundle mainBundle] loadNibNamed:@"PhotosLandscape" owner:self options:nil]; 
    }else{ 
     [[NSBundle mainBundle] loadNibNamed:@"PhotosPortrait" owner:self options:nil]; 
    } 
} 

- (BOOL)currentlyInLandscapeMode:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (UIInterfaceOrientationIsLandscape(interfaceOrientation)); 
} 

如何切換xib並保持我以前的視圖/ xib中的所有狀態?

UPDATE

原來我IBOutlets仍然工作,但我的刷卡未註冊

+0

在第二XIB正確接線的iboutlets重新註冊的刷卡事件? – TigerCoding 2012-02-15 00:01:33

+0

是 - 景觀以端口視圖的副本開始,因此除了視圖本身上的位置(xy座標系)之外,xib中的所有內容都是相同的, – 2012-02-15 00:05:03

回答

2

您不能使用榫文件奠定了現有對象。一個筆尖文件存儲爲一個存檔的對象圖形,因此當您加載一個筆尖時,使用NSBundleloadNibNamed:UIViewControllerinitWithNibName:,一組新的對象被實例化。

解決這個問題的唯一方法是使用loadNibNamed實例化一個新的對象集,並用自己的frame特性爲現有的對象,這不是一個很好的解決方案設置frame秒。

0

原來我只是需要每個筆尖被加載(像這樣)後

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if ([self currentlyInLandscapeMode:toInterfaceOrientation]) { 
     [[NSBundle mainBundle] loadNibNamed:@"VotePhotosLandscape" owner:self options:nil]; 
    }else{ 
     [[NSBundle mainBundle] loadNibNamed:@"VotePhotosViewController" owner:self options:nil]; 
    } 
    [self wireupSwipeEvents]; 
} 

- (BOOL)currentlyInLandscapeMode:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (UIInterfaceOrientationIsLandscape(interfaceOrientation)); 
} 

- (void)wireupSwipeEvents 
{ 
    UISwipeGestureRecognizer *recognizer; 
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 
    [recognizer setDirection:UISwipeGestureRecognizerDirectionLeft]; 
    [[self view] addGestureRecognizer:recognizer]; 
    [recognizer release]; 
} 
相關問題