我會從UIAlertView
按鈕打開一個UIViewController
,但它不起作用。從UIAlertView按鈕以編程方式推送視圖?
當用戶終止比賽,我表現出一些文字和兩個按鈕UIAlertView
:「確定」來關閉提醒和「分數」打開比分頁。
這是實際UIAlertView
:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"YOU WIN!"
message:[NSString stringWithFormat:@"You win a game in %d seconds!",seconds]
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:@"Score", nil];
[alert show];
,這是代碼推的觀點:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Score"]){
ScoreViewController *score = [[ScoreViewController alloc]init];
[[self navigationController] pushViewController:score animated:YES];
}
}
我得到是一個完全黑屏。有人能幫我嗎?我無法弄清楚我做錯了什麼。
PS:ScoreViewController
從根視圖中有一個segue,但我當然不能從故事板創建一個新的,因爲我想通過編程方式從alert view按鈕執行segue。
希望我已經清楚,任何幫助將非常感激!
它看起來並不像是在執行segue。以編程方式執行Storyboard segue的方法是'performSegueWithIdentifier:sender:' – hgwhittle
ops對不起,您是對的!我之前嘗試過使用segue,但沒有工作,所以我搜索並找到'pushViewController:animated:',然後我忘記更改代碼。我將編輯我的問題,但'執行SegueWithIdentifier:發件人:'使應用程序崩潰與'線程1:信號SIGABRT' –