我試圖根據用戶在UIAlertView
中的選擇來更改視圖控制器。我是客觀的新手,並且遇到了一些麻煩。使用UIAlertView在ViewControllers之間導航
當用戶按下「我完成了」時,我希望應用程序導航回到先前的視圖控制器。當用戶按下「Scoreboard」時,我希望應用程序導航到下一個視圖控制器。
UIAlertView *jigsawCompleteAlert = [[UIAlertView alloc] //show alert box with option to play or exit
initWithTitle: @"Congratulations!"
message:completedMessage
delegate:self
cancelButtonTitle:@"I'm done"
otherButtonTitles:@"Play again", @"Scoreboard",nil];
[jigsawCompleteAlert show];
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSLog(@"Cancel Tapped.");
[self.navigationController popViewControllerAnimated:YES];
}
else if (buttonIndex == 1) {
NSLog(@"GO tapped.");
startDate = [NSDate date];
// Create the stop watch timer that fires every 10 ms
stopWatchTimer = [NSTimer
scheduledTimerWithTimeInterval:1.0/10.0
target:self
selector:@selector(updateTimer)
userInfo:nil
repeats:YES];
} else if (buttonIndex == 2) {
NSLog(@"Scoreboard tapped.");
}
}
popView部件正在工作,應用程序導航回一個視圖控制器。我不知道如何讓應用程序向前移動一個視圖控制器。我知道這與pushViewController
有關,但我只看到很老的和矛盾的文章,詳細說明如何做到這一點。
我很感謝這個幫助,謝謝。
謝謝。我是否需要先導入視圖控制器?我正在使用ARC,因此我使用的代碼是'UIViewController * ctrl = [[UIViewController alloc] initWithNibName:@「AssignmentViewController3」bundle:nil]; [self.navigationController pushViewController:ctrl animated:YES];'。我目前在viewcontroller2和viewcontroller3之間沒有segue,所以我得到了「scene unreachable」警告。這些文件名爲AssignmentViewController3.h和AssignmentViewController3.m,但我不確定這是否意味着AssignmentViewController3是NIB名稱。再次感謝 – garethdn 2012-04-09 15:00:15
是的。添加行#import「AssignmentViewController3.h」。而不是UIViewController類型AssignmentViewController3 – beryllium 2012-04-09 15:07:36
我得到一個SIGABRT錯誤 - '無法加載NIB束.....名稱AssignmentViewController3'。我現在使用的代碼是'AssignmentViewController3 * ctrl = [[AssignmentViewController3 alloc] initWithNibName:@「AssignmentViewController3」bundle:nil]; [self.navigationController pushViewController:ctrl animated:YES];'。我不確定是否發生這種情況,因爲我從來沒有明確設置NIB名稱,因爲我不知道如何? – garethdn 2012-04-09 15:15:30