简体   繁体   中英

Passing variables to the view from AppDelegate

i open a view in AppDelegate

with:

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];
}

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.

Namely didFailLoadWithError - see the UIWebViewDelegate Protocol References for more.

Maybe its just a typo on your 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. My guess is that you've forgotten to bind your pushDetails outlet to the webview in your nib file.

You could create lets say a file that holds all your global variables lets call it GlobalVariables.h and .m. In the GlobalVariables.h file add this

extern NSURL *seminarurl;

@interface GlobalVariables

@property (retain, nonatomic) NSURL *seminarurl;    

@end

and in the GlobalVariables.m file add

#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.

  1. make your property retained. ex >> @property (nonatomic,retain) .

  2. if the url is a property in your app delegate .. you can access it like this

    [UIApplication SharedApplication].delegate.yourpropertyname;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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