2013-04-13 26 views
0

我正在使用UIPageViewController處理數據輸入,其中最後一頁是活動記錄,而以前的頁面是無法編輯的舊記錄。所以我需要一種方法來驗證用戶想要離開最後一頁,同時允許所有其他頁面照常導航。UIPageViewController - 使用警報驗證翻頁

理想情況下,我真的可以使用 - (BOOL)pageShouldTurn方法,但不存在。

有誰知道一種方法來檢測一個頁面是否要卸載,然後根據某些條件停止翻頁?我對手勢識別器方法沒有任何好運,因爲即使設置了委託,它們似乎也不會被觸發。

感謝邁克爾,我已經添加到了我的pageViewController不,我需要這正是:

-(void)pageViewController:(UIPageViewController *)pvc willTransitionToViewControllers:(NSArray *)pendingViewControllers 
{ 
    if ([pvc.viewControllers.lastObject pageIndex] == [self.pageDataSource.allObjects count]) { 
     UIAlertView *alertDialog; 
     alertDialog = [[UIAlertView alloc] 
         initWithTitle:@"Are You Done?" 
         message:@"Once you leave this page you can't edit this record again" 
         delegate:self 
         cancelButtonTitle:@"OK" 
         otherButtonTitles: nil]; 
     [alertDialog show]; 
    } 
} 

所以警告框,從打開一次停止頁面。當它被解散時,用戶可以改變頁面。我的版本檢查以確保這隻發生在最後一頁上,你可以刪除'if'語句並在每一頁上都發出警報,但這會很煩人。

回答

0

對我來說似乎至少有兩種選擇。

第一,你有"- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers"。您可能可以在那裏進行轉換並拒絕/強制重置舊頁面。

或者,您現在可以繼承「UIPageViewController」,並在你的子類控制器,你可以定義一個新的委託協議(包含所有原始UIPageViewControllerDelegate「的方法),你可以添加自己的」 -(BOOL) pageShouldTurn「協議方法。

這兩種可能性都需要iOS 6.

+0

感謝邁克爾,他們看起來都不錯,讓我玩吧,我會盡快回復你(我正在使用iOS 6,所以沒有問題) – Chris

+0

我沒有意識到willTransitionToViewControllers方法,所以非常感謝!然後,我必須確定我當前的頁面不是太難,我要添加我的最終頁面上面的方法可以幫助任何可能需要這個的人。再次感謝! – Chris