2012-01-15 73 views
0

到視圖我打開的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]; 
} 

但webview是空的...我做錯了什麼?

第二個問題如何關閉我打開的視圖?

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

不工作:(

回答

0

可以將您的視圖控制器內實現UIWebViewDelegate協議和自己獲取結果/錯誤消息

didFailLoadWithError - 看到UIWebViewDelegate Protocol References更多

也許它只是你的網址上的拼寫錯誤

例如:

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

有沒有錯誤...如果我在我的push詳細信息視圖中寫這個信息seminarurl = [NSURL URLWithString:@「http://google.de」];一切都很好 – 2012-01-15 17:37:35

+0

那麼它一定是'resourcePathURL'的錯誤內容。 NSLog那一個,檢查一下自己。 – Till 2012-01-15 18:30:30

0

您尚未指定pushDetails是什麼,但我假設它是您的PushDetail控制器上的UIWebview的IBOutlet。我的猜測是,您忘記了將您的pushDetails插件綁定到您的nib文件中的webview。

+0

抱歉,pushdetail是一個uiwebview控制器 – 2012-01-15 18:17:02

+0

是的,這就是我所設想的。你有沒有檢查你是否限制了出路? – 2012-01-17 09:17:23

0

您可以創建讓我們說一個文件,其中包含所有的全局變量可以稱之爲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文件。

0
  1. 使您的財產保留。 ex >>@property (nonatomic,retain)

  2. 如果該URL是在你的應用程序委託的屬性..你可以訪問它像這樣

    [UIApplication的SharedApplication] .delegate.yourpropertyname;