Ios 解除ViewControllerInitiated后未加载视图

Ios 解除ViewControllerInitiated后未加载视图,ios,uiview,uiviewcontroller,webview,Ios,Uiview,Uiviewcontroller,Webview,我的firstViewController中有一个webView。 我让用户在另一个viewController(secondViewController)中更改url中的一些参数 我展示了第二个视图控制器,让用户可以这样做。 完成后(他单击“完成”按钮并调用dismissViewControllerAnimated), 我想获得url更改并将其加载到视图控制器webView。但是webView似乎没有加载。。。。这就是问题所在 这里有一个例子 firstViewController.h: ..

我的firstViewController中有一个webView。 我让用户在另一个viewController(secondViewController)中更改url中的一些参数

我展示了第二个视图控制器,让用户可以这样做。 完成后(他单击“完成”按钮并调用dismissViewControllerAnimated), 我想获得url更改并将其加载到视图控制器webView。但是webView似乎没有加载。。。。这就是问题所在

这里有一个例子

firstViewController.h:

.......
#import "SecondViewController.h"
.....
@property (strong, nonatomic) IBOutlet UIWebView *webView;
.....
@synthesize webView;

SecondViewController *csvc = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
csvc.OLDurlInWebView = webView.request.URL.absoluteString;
csvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:csvc animated:YES completion:nil];
......
......
......
//I'm calling this method after dismissViewControllerAnimated from secondViewControllerClass
-(void)showInView:(NSString *)str {
    [self view];
    [self loadView];
    [self view];
    [self openURL:[NSURL URLWithString:str]];
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"TEST" delegate:nil cancelButtonTitle:@"TEST" destructiveButtonTitle:nil otherButtonTitles:@"TEST", nil];
    NSLog(@"current:%@ isLoaded:%d",webView.request.URL.absoluteString,self.isViewLoaded); //output 'current:(null) isLoaded:1'
    [sheet showInView:self.view];//this sheet test will not show, the app will crash:'Sheet can not be presented because the view is not in a window:.......'
}
-(void)openURL:(NSURL *)url {
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    NSLog(@"Trying to open %@ in webbrowser", url);

    [webView loadRequest:request];

}
.......
#import "FirstController.h"
.......
@interface SecondViewController : UIViewController {
NSString *OLDurlInWebView;
.......
}
.......
@property (strong, nonatomic) NSString *OLDurlInWebView;
- (IBAction)doneButton:(id)sender;
.......
@synthesize OLDurlInWebView;

......
- (IBAction)doneButton:(id)sender {
    [self dismissViewControllerAnimated:NO/*YES*/ completion:nil]; //completion???
}
-(void)viewDidDisappear:(BOOL)animated {
    NSLog(@"SecondViewC didDisappear");
    WebViewController *wb = [self.storyboard instantiateViewControllerWithIdentifier:@"web"];

    NSString *newurl = @"http://facebook.com"; //let the user load facebook as example
    [wb view];
    [wb loadView]; //testing everything, nothing works
    [wb view];

    [wb performSelector:@selector(showInView:) withObject:newurl afterDelay:5];//the webView will not load after 5 seconds. Why?
}
firstViewController.m:

.......
#import "SecondViewController.h"
.....
@property (strong, nonatomic) IBOutlet UIWebView *webView;
.....
@synthesize webView;

SecondViewController *csvc = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
csvc.OLDurlInWebView = webView.request.URL.absoluteString;
csvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:csvc animated:YES completion:nil];
......
......
......
//I'm calling this method after dismissViewControllerAnimated from secondViewControllerClass
-(void)showInView:(NSString *)str {
    [self view];
    [self loadView];
    [self view];
    [self openURL:[NSURL URLWithString:str]];
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"TEST" delegate:nil cancelButtonTitle:@"TEST" destructiveButtonTitle:nil otherButtonTitles:@"TEST", nil];
    NSLog(@"current:%@ isLoaded:%d",webView.request.URL.absoluteString,self.isViewLoaded); //output 'current:(null) isLoaded:1'
    [sheet showInView:self.view];//this sheet test will not show, the app will crash:'Sheet can not be presented because the view is not in a window:.......'
}
-(void)openURL:(NSURL *)url {
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    NSLog(@"Trying to open %@ in webbrowser", url);

    [webView loadRequest:request];

}
.......
#import "FirstController.h"
.......
@interface SecondViewController : UIViewController {
NSString *OLDurlInWebView;
.......
}
.......
@property (strong, nonatomic) NSString *OLDurlInWebView;
- (IBAction)doneButton:(id)sender;
.......
@synthesize OLDurlInWebView;

......
- (IBAction)doneButton:(id)sender {
    [self dismissViewControllerAnimated:NO/*YES*/ completion:nil]; //completion???
}
-(void)viewDidDisappear:(BOOL)animated {
    NSLog(@"SecondViewC didDisappear");
    WebViewController *wb = [self.storyboard instantiateViewControllerWithIdentifier:@"web"];

    NSString *newurl = @"http://facebook.com"; //let the user load facebook as example
    [wb view];
    [wb loadView]; //testing everything, nothing works
    [wb view];

    [wb performSelector:@selector(showInView:) withObject:newurl afterDelay:5];//the webView will not load after 5 seconds. Why?
}
secondViewController.h:

.......
#import "SecondViewController.h"
.....
@property (strong, nonatomic) IBOutlet UIWebView *webView;
.....
@synthesize webView;

SecondViewController *csvc = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
csvc.OLDurlInWebView = webView.request.URL.absoluteString;
csvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:csvc animated:YES completion:nil];
......
......
......
//I'm calling this method after dismissViewControllerAnimated from secondViewControllerClass
-(void)showInView:(NSString *)str {
    [self view];
    [self loadView];
    [self view];
    [self openURL:[NSURL URLWithString:str]];
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"TEST" delegate:nil cancelButtonTitle:@"TEST" destructiveButtonTitle:nil otherButtonTitles:@"TEST", nil];
    NSLog(@"current:%@ isLoaded:%d",webView.request.URL.absoluteString,self.isViewLoaded); //output 'current:(null) isLoaded:1'
    [sheet showInView:self.view];//this sheet test will not show, the app will crash:'Sheet can not be presented because the view is not in a window:.......'
}
-(void)openURL:(NSURL *)url {
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    NSLog(@"Trying to open %@ in webbrowser", url);

    [webView loadRequest:request];

}
.......
#import "FirstController.h"
.......
@interface SecondViewController : UIViewController {
NSString *OLDurlInWebView;
.......
}
.......
@property (strong, nonatomic) NSString *OLDurlInWebView;
- (IBAction)doneButton:(id)sender;
.......
@synthesize OLDurlInWebView;

......
- (IBAction)doneButton:(id)sender {
    [self dismissViewControllerAnimated:NO/*YES*/ completion:nil]; //completion???
}
-(void)viewDidDisappear:(BOOL)animated {
    NSLog(@"SecondViewC didDisappear");
    WebViewController *wb = [self.storyboard instantiateViewControllerWithIdentifier:@"web"];

    NSString *newurl = @"http://facebook.com"; //let the user load facebook as example
    [wb view];
    [wb loadView]; //testing everything, nothing works
    [wb view];

    [wb performSelector:@selector(showInView:) withObject:newurl afterDelay:5];//the webView will not load after 5 seconds. Why?
}
secondViewController.m:

.......
#import "SecondViewController.h"
.....
@property (strong, nonatomic) IBOutlet UIWebView *webView;
.....
@synthesize webView;

SecondViewController *csvc = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
csvc.OLDurlInWebView = webView.request.URL.absoluteString;
csvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:csvc animated:YES completion:nil];
......
......
......
//I'm calling this method after dismissViewControllerAnimated from secondViewControllerClass
-(void)showInView:(NSString *)str {
    [self view];
    [self loadView];
    [self view];
    [self openURL:[NSURL URLWithString:str]];
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"TEST" delegate:nil cancelButtonTitle:@"TEST" destructiveButtonTitle:nil otherButtonTitles:@"TEST", nil];
    NSLog(@"current:%@ isLoaded:%d",webView.request.URL.absoluteString,self.isViewLoaded); //output 'current:(null) isLoaded:1'
    [sheet showInView:self.view];//this sheet test will not show, the app will crash:'Sheet can not be presented because the view is not in a window:.......'
}
-(void)openURL:(NSURL *)url {
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    NSLog(@"Trying to open %@ in webbrowser", url);

    [webView loadRequest:request];

}
.......
#import "FirstController.h"
.......
@interface SecondViewController : UIViewController {
NSString *OLDurlInWebView;
.......
}
.......
@property (strong, nonatomic) NSString *OLDurlInWebView;
- (IBAction)doneButton:(id)sender;
.......
@synthesize OLDurlInWebView;

......
- (IBAction)doneButton:(id)sender {
    [self dismissViewControllerAnimated:NO/*YES*/ completion:nil]; //completion???
}
-(void)viewDidDisappear:(BOOL)animated {
    NSLog(@"SecondViewC didDisappear");
    WebViewController *wb = [self.storyboard instantiateViewControllerWithIdentifier:@"web"];

    NSString *newurl = @"http://facebook.com"; //let the user load facebook as example
    [wb view];
    [wb loadView]; //testing everything, nothing works
    [wb view];

    [wb performSelector:@selector(showInView:) withObject:newurl afterDelay:5];//the webView will not load after 5 seconds. Why?
}
好的,从一开始:

在firstViewController中:

.......
#import "SecondViewController.h"
.....
@property (strong, nonatomic) IBOutlet UIWebView *webView;
.....
@synthesize webView;

SecondViewController *csvc = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
csvc.OLDurlInWebView = webView.request.URL.absoluteString;
csvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:csvc animated:YES completion:nil];
......
......
......
//I'm calling this method after dismissViewControllerAnimated from secondViewControllerClass
-(void)showInView:(NSString *)str {
    [self view];
    [self loadView];
    [self view];
    [self openURL:[NSURL URLWithString:str]];
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"TEST" delegate:nil cancelButtonTitle:@"TEST" destructiveButtonTitle:nil otherButtonTitles:@"TEST", nil];
    NSLog(@"current:%@ isLoaded:%d",webView.request.URL.absoluteString,self.isViewLoaded); //output 'current:(null) isLoaded:1'
    [sheet showInView:self.view];//this sheet test will not show, the app will crash:'Sheet can not be presented because the view is not in a window:.......'
}
-(void)openURL:(NSURL *)url {
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    NSLog(@"Trying to open %@ in webbrowser", url);

    [webView loadRequest:request];

}
.......
#import "FirstController.h"
.......
@interface SecondViewController : UIViewController {
NSString *OLDurlInWebView;
.......
}
.......
@property (strong, nonatomic) NSString *OLDurlInWebView;
- (IBAction)doneButton:(id)sender;
.......
@synthesize OLDurlInWebView;

......
- (IBAction)doneButton:(id)sender {
    [self dismissViewControllerAnimated:NO/*YES*/ completion:nil]; //completion???
}
-(void)viewDidDisappear:(BOOL)animated {
    NSLog(@"SecondViewC didDisappear");
    WebViewController *wb = [self.storyboard instantiateViewControllerWithIdentifier:@"web"];

    NSString *newurl = @"http://facebook.com"; //let the user load facebook as example
    [wb view];
    [wb loadView]; //testing everything, nothing works
    [wb view];

    [wb performSelector:@selector(showInView:) withObject:newurl afterDelay:5];//the webView will not load after 5 seconds. Why?
}
我正在演示第二个ViewController

现在我们在secondViewController:

.......
#import "SecondViewController.h"
.....
@property (strong, nonatomic) IBOutlet UIWebView *webView;
.....
@synthesize webView;

SecondViewController *csvc = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
csvc.OLDurlInWebView = webView.request.URL.absoluteString;
csvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:csvc animated:YES completion:nil];
......
......
......
//I'm calling this method after dismissViewControllerAnimated from secondViewControllerClass
-(void)showInView:(NSString *)str {
    [self view];
    [self loadView];
    [self view];
    [self openURL:[NSURL URLWithString:str]];
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"TEST" delegate:nil cancelButtonTitle:@"TEST" destructiveButtonTitle:nil otherButtonTitles:@"TEST", nil];
    NSLog(@"current:%@ isLoaded:%d",webView.request.URL.absoluteString,self.isViewLoaded); //output 'current:(null) isLoaded:1'
    [sheet showInView:self.view];//this sheet test will not show, the app will crash:'Sheet can not be presented because the view is not in a window:.......'
}
-(void)openURL:(NSURL *)url {
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    NSLog(@"Trying to open %@ in webbrowser", url);

    [webView loadRequest:request];

}
.......
#import "FirstController.h"
.......
@interface SecondViewController : UIViewController {
NSString *OLDurlInWebView;
.......
}
.......
@property (strong, nonatomic) NSString *OLDurlInWebView;
- (IBAction)doneButton:(id)sender;
.......
@synthesize OLDurlInWebView;

......
- (IBAction)doneButton:(id)sender {
    [self dismissViewControllerAnimated:NO/*YES*/ completion:nil]; //completion???
}
-(void)viewDidDisappear:(BOOL)animated {
    NSLog(@"SecondViewC didDisappear");
    WebViewController *wb = [self.storyboard instantiateViewControllerWithIdentifier:@"web"];

    NSString *newurl = @"http://facebook.com"; //let the user load facebook as example
    [wb view];
    [wb loadView]; //testing everything, nothing works
    [wb view];

    [wb performSelector:@selector(showInView:) withObject:newurl afterDelay:5];//the webView will not load after 5 seconds. Why?
}
用户现在将更改url,但在本例中,他将更改facebook.com的url

现在我们将把这个新的url(facebook.com)发送回firstViewController。用户 单击“完成”按钮,将调用DismissViewControllerInitiated

尝试使用此新url(facebook)返回firstViewController。

我已经测试了我所知道的一切,但这还不够。我已经测试过从secondViewController调用firstViewController中的普通函数。webView将无法加载请求

然后,我测试将代码放入ViewDidEnglish,并给视图5秒钟的加载时间,但它不起作用

不久前,当我的应用程序处理应用程序委托中的URL方案链接时,我遇到了这个问题。 -(BOOL)应用程序:(UIApplication*)应用程序handleOpenURL:(NSURL*)url 例如,如果您不想从url方案链接加载另一个带有url或文本的webView/标签? 如何从应用程序代理执行此操作?这与上述问题相同

我做错了什么/我不知道什么?
如何“等待”视图加载,然后能够加载例如带有url的webView。?

必须在第一个VC上调用Disclose。您可以从第二个开始这样做:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
此外,要获取信息,可以在第一个视图中使用委托或属性:

解雇前致电:

[self.presetingViewController setMyProperty:urlToPassBack];

setMyProperty将是PresettingViewController上的属性。当您将UIViewController子类化,然后将其用作显示viewController时,您可以定义它。