2011-10-28 28 views
0

我在UIWebView上有一個帶有登錄屏幕的標籤欄應用程序,然後當用戶登錄時,所有其他標籤都可以使用相同的登錄名。 登錄按鈕也在網站上,我無法控制該代碼。參考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查看視圖控制器的屬性。然後:

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

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

明天我會看看這個選項,並提供我的反饋謝謝。 –

相關問題