程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-UIAlertView按鈕到其他視圖控制器

ios-UIAlertView按鈕到其他視圖控制器

編輯:編程綜合問答
UIAlertView按鈕到其他視圖控制器

在應用中有一個uialertview,有兩個按鈕,第一個是取消按鈕,另一個是OK按鈕,在按下OK按鈕時,應該跳到一個帶有storyboard標志符的視圖控制器RootView。應該怎麼實現?

- (void)showAlarm:(NSString *)text {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"show alarm"
                                                            message:text delegate:self                                                  cancelButtonTitle:@"cancel"
                                                  otherButtonTitles:@"ok", nil];
        [alertView show];
    }
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
        if (buttonIndex == 0){
             NSLog(@"cancel"); 
        }else if (buttonIndex == 1){
             NSLog(@"ok");
           UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
           UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"navigationController"];
            [navigationController presentViewController:[storyboard instantiateViewControllerWithIdentifier:@"RootView"] animated:YES completion:nil];
   }
    }

最佳回答:


可嘗試在當前控制器中,彈出identifier為navigationController的控制器,在navigationController控制器中再push到rootView.改成這樣試試

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
    UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"navigationController"];
if (navigationController) {
   [self presentViewController:navigationController animated:YES completion:nil];
}

接著在identifier 為navigationcontroller的控制器的viewwillappear中push到rootview

-(void)viewWillAppear {
     RootViewController *rootController=[storyboard instantiateViewControllerWithIdentifier:@"RootView"];

     if (rootController) {
            [self.navigationController pushViewController:rootController animation:NO];
     }
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved