我正在使用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'語句並在每一頁上都發出警報,但這會很煩人。
感謝邁克爾,他們看起來都不錯,讓我玩吧,我會盡快回復你(我正在使用iOS 6,所以沒有問題) – Chris
我沒有意識到willTransitionToViewControllers方法,所以非常感謝!然後,我必須確定我當前的頁面不是太難,我要添加我的最終頁面上面的方法可以幫助任何可能需要這個的人。再次感謝! – Chris