简体   繁体   English

从AppDelegate将变量传递到视图

[英]Passing variables to the view from AppDelegate

i open a view in AppDelegate 我在AppDelegate中打开视图

with: 与:

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 PushDetail.h

@property (nonatomic) NSURL *seminarurl;

PushDetail.m PushDetail.m

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

But the webview is empty... what I do wrong? 但是网络视图是空的...我做错了什么?

and the second question how to close the view I opened? 第二个问题是如何关闭我打开的视图?

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

does not work :( 不起作用:(

You may implement the UIWebViewDelegate protocol within your view controller and fetch the results/error messages yourself. 您可以在视图控制器中实现UIWebViewDelegate协议,并自己获取结果/错误消息。

Namely didFailLoadWithError - see the UIWebViewDelegate Protocol References for more. didFailLoadWithError有关更多信息,请参见UIWebViewDelegate协议参考

Maybe its just a typo on your URL. 也许只是您URL上的错字。

Example: 例:

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

You've not specified what pushDetails is, but I'm assuming it's an IBOutlet to a UIWebview on your PushDetail controller. 您尚未指定pushDetails是什么,但我假设它是PushDetail控制器上UIWebview的IBOutlet。 My guess is that you've forgotten to bind your pushDetails outlet to the webview in your nib file. 我的猜测是您忘记了将pushDetails出口绑定到nib文件中的webview。

You could create lets say a file that holds all your global variables lets call it GlobalVariables.h and .m. 您可以创建一个包含所有全局变量的文件,将其命名为GlobalVariables.h和.m。 In the GlobalVariables.h file add this 在GlobalVariables.h文件中添加此

extern NSURL *seminarurl;

@interface GlobalVariables

@property (retain, nonatomic) NSURL *seminarurl;    

@end

and in the GlobalVariables.m file add 并在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

So when you want to access it or assign a variable to it, it would just be like accessing or assigning any other variable. 因此,当您要访问它或为其分配变量时,就像访问或分配任何其他变量一样。 Just remember to import 'GlobalVariables.h' into which ever .m file you are using it in. 只需记住将“ GlobalVariables.h”导入到您正在其中使用的任何.m文件中即可。

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

  2. if the url is a property in your app delegate .. you can access it like this 如果url是您的应用程序委托中的一个属性..您可以像这样访问它

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

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

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