繁体   English   中英

从AppDelegate将变量传递到视图

[英]Passing variables to the view from AppDelegate

我在AppDelegate中打开视图

与:

AppDelegate

PushDetail *pushdtls = [[PushDetail alloc] initWithNibName:nil bundle:nil];   
pushdtls.seminarurl = [NSURL URLWithString:resourcePathURL]; /passing URL
[self.window presentModalViewController:pushdtls animated:YES];

PushDetail.h

@property (nonatomic) NSURL *seminarurl;

PushDetail.m

- (void)viewDidLoad
{
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:seminarurl];
    [pushDetails loadRequest:requestObj];
}

但是网络视图是空的...我做错了什么?

第二个问题是如何关闭我打开的视图?

- (IBAction) closeNews{
    //[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    //[self release];
    [self dismissModalViewControllerAnimated:YES];
}

不起作用:(

您可以在视图控制器中实现UIWebViewDelegate协议,并自己获取结果/错误消息。

didFailLoadWithError有关更多信息,请参见UIWebViewDelegate协议参考

也许只是您URL上的错字。

例:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"oops, failed with error: %@", error);
}

您尚未指定pushDetails是什么,但我假设它是PushDetail控制器上UIWebview的IBOutlet。 我的猜测是您忘记了将pushDetails出口绑定到nib文件中的webview。

您可以创建一个包含所有全局变量的文件,将其命名为GlobalVariables.h和.m。 在GlobalVariables.h文件中添加此

extern NSURL *seminarurl;

@interface GlobalVariables

@property (retain, nonatomic) NSURL *seminarurl;    

@end

并在GlobalVariables.m文件中添加

#import "GlobalVariables.h"

@implements GlobalVariables

@synthesize seminarurl;

NSURL *seminarurl; // You could add what your URL is here as well you would just use '='

@end

因此,当您要访问它或为其分配变量时,就像访问或分配任何其他变量一样。 只需记住将“ GlobalVariables.h”导入到您正在其中使用的任何.m文件中即可。

  1. 保留您的财产。 例如>> @property (nonatomic,retain)

  2. 如果url是您的应用程序委托中的一个属性..您可以像这样访问它

    [UIApplication SharedApplication] .delegate。您的属性名;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM