Iphone 从AppDelegate向视图传递变量

Iphone 从AppDelegate向视图传递变量,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我在AppDelegate中打开一个视图 PushDetail *pushdtls = [[PushDetail alloc] initWithNibName:nil bundle:nil]; pushdtls.seminarurl = [NSURL URLWithString:resourcePathURL]; /passing URL [self.window presentModalViewController:pushdtls animated:YES]; 与: AppDeleg

我在AppDelegate中打开一个视图

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

AppDelegate

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

@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
-有关更多信息,请参阅

也许这只是你的URL上的一个输入错误

例如:

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

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

您可以创建一个包含所有全局变量的文件,在Glo中称之为GlobalVariables.h和.mbalVariables.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”导入到您正在使用它的ever.m文件中

  • 保留您的属性。ex>
    @property(非原子,保留)

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

    [UIApplication SharedApplication].delegate.yourpropertyname


  • 没有错误…如果我在推送详细信息视图seminarurl=[NSURL URLWithString:@“中写入此内容,一切正常,那么它一定是
    resourcePathURL
    的错误内容。请记录该内容并检查您自己。抱歉,推送详细信息是一个带有uiwebviewYes的控制器。这是我假设的。您当时是否检查了是否绑定了插座?