[英]Present View Controller not working with ios 9
當前視圖控制器不適用於 ios 9,當我按下按鈕時,它沒有重定向到當前視圖控制器。
為什么會發生這種情況?
我試過下面的代碼
RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:@"Registration" bundle:nil] instantiateViewControllerWithIdentifier:@"RegistrationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
我也試過下面的代碼
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Registration"
bundle:nil];
RegistrationViewController *add =
[storyboard instantiateViewControllerWithIdentifier:@"RegistrationViewController"];
[self presentViewController:add animated:YES completion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:add
animated:YES
completion:nil];
});
}];
編輯
我的完整代碼在這里。 我正在使用 Xcode 7 並在 ios 9 上運行它
#import "LoginViewController.h"
#import "RegistrationViewController.h"
@interface LoginViewController ()
@end
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)actionRegistrationClicked:(id)sender
{
RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:@"Registration" bundle:nil] instantiateViewControllerWithIdentifier:@"RegistrationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
}
@end
注冊視圖控制器
#import "RegistrationViewController.h"
@interface RegistrationViewController ()
@end
@implementation RegistrationViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
確保presentViewController為零。 如果presentViewController不是nil,則將代碼更改為以下內容。
RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:@"Registration" bundle:nil] instantiateViewControllerWithIdentifier:@"RegistrationViewController"];
if ([self presentedViewController]) {
[[self presentedViewController] dismissViewControllerAnimated:NO completion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:viewController animated:YES completion:nil];
});
}];
} else {
[self presentViewController:viewController animated:YES completion:nil];
}
有時主循環會出現錯誤,嘗試以這種方式呈現
RegistrationViewController *viewController = [[UIStoryboard storyboardWithName:@"Registration" bundle:nil] instantiateViewControllerWithIdentifier:@"RegistrationViewController"];
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:viewController animated:YES completion:nil];
});
嘗試viewDidAppear in
-(void)viewDidAppear:(BOOL)animated{
[self presentViewController:viewController animated:YES completion:nil];
}
請嘗試以下代碼:
RegistrationViewController * viewController = [[self.storyboard instantiateViewControllerWithIdentifier:@"RegistrationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.