2011-10-28 9 views
0

UIWebViewにログイン画面のタブバーアプリケーションがあり、ユーザーがログインすると他のすべてのタブで同じログインを使用できます。 ログインボタンもWebサイトにあり、私はそのコードを制御できません。iOSアプリケーション内の別のタブバーを参照

ユーザーがログインしていない場合、他のタブにエラーが表示されますが、ログインページが表示されているかどうかを確認するために、アクティブなタブを最初のものと比較するif文を実行できますか?アイデアはこのようになります。

if(tab bar 1 == index.html) { 
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]]; 
else{ 
NSString *urlAddress = @"website that is requested";  
NSURL *url = [NSURL URLWithString:urlAddress]; 
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
[webView loadRequest:requestObj]; 
} 

if文の後には何を挿入しますか?

乾杯

答えて

0

`[[self.tabBarController viewControllers] objectAtIndex:0]。最初のタブのビューコントローラを返します。 WebビューをView Controllerのプロパティにします。次に:

UIViewController *loginViewController = [[self.tabBarController viewControllers] objectAtIndex:0]; 
UIWebView *loginWebView [loginViewController webView]; 
NSString *currentURL = [loginWebView stringByEvaluatingJavaScriptFromString:@"window.location"]; 

if (currentURL == someURL) { 
    ... 
} 
+0

明日このオプションを見ていただき、ありがとうございます。 –

関連する問題