2015-04-05 55 views
0

我有兩個視圖控制器之一是informationViewController和另一個InformationDetailedViewController。有按鈕的動作我加載相應的URL PDF文件Inital負載視圖控制器將不響應網絡視圖

// InformationViewController.m 
     // About Us button clicked 
     -(void)aboutUsAction:(id)sender{ 
      [informationDetailedViewController showInformation:0]; 
      [self.navigationController pushViewController:informationDetailedViewController animated:YES]; 
     } 

     // Terms and condition button clicked 
     -(void)termsAndConditionAction:(id)sender{ 
      [informationDetailedViewController showInformation:1]; 
      [self.navigationController pushViewController:informationDetailedViewController animated:YES]; 
     } 

    // InformationDetailedViewController.m  
    - (void)viewDidLoad{ 

     [super viewDidLoad];  
     // create a webview 
     webInfoDetailed = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height)]; 
     webInfoDetailed.scalesPageToFit = YES; 
     [webInfoDetailed setBackgroundColor:[UIColor whiteColor]]; 
     [self.view addSubview:webInfoDetailed];  
    } 

    -(void)viewWillAppear:(BOOL)animated{ 
     [super viewWillAppear:YES]; 
    } 


    -(void)viewDidAppear:(BOOL)animated{ 
     [super viewDidAppear:YES]; 
    } 

     // InInformationDetailedViewController.1 
     -(void)showInformation:(int)informationId { 

      NSString *informationType = @""; 
      switch (informationId) { 
       case 0: 
        self.title = @"About Us"; 
        informationType = KHABOUTUS; 
        break; 
       case 1: 
        self.title = @"Disclaimer"; 

        informationType = KHDISCLAIMER; 
        break; 
       default: 
        break; 
      } 

      NSURL *targetURL = [NSURL URLWithString:informationType]; 
      NSURLRequest *request = [NSURLRequest requestWithURL:targetURL]; 
      [webInfoDetailed loadRequest:request]; 
     } 

的問題是在初始加載(第一次加載)的網址是不是裝上webView的兩粒扣。 當點擊返回,然後點擊關於我們或條款和條件它的工作完美。它是我在這裏失蹤的非常小的東西。 @所有感謝提前

+1

它不起作用,因爲在調用showInformation時Web視圖未加載:0。你在這個聲明之後推動它。然後加載webview。所以要解決這個問題。您將一個整數傳遞給詳細視圖。從詳細視圖中,您應該調用showInformation函數:x。 x是整數屬性。讓我知道你是否需要這個代碼。 – Jassi 2015-04-05 14:16:40

+0

@Jassi感謝您的輸入!它的固定 - (void)viewWillAppear:(BOOL)動畫{super viewWillAppear:YES]; NSLog(@「typeID%d中的值」,typeID); [self showInformation:typeID]; } – kiran 2015-04-05 14:46:30

回答

1

擴大Jassi的評論,這裏是一個代碼片段,可以幫助你。

InformationDetailedViewController.h

@property int informationId; // make it as a member of VC. 

變化showInformation方法,使得它使用informationId構件代替參數在

在InformationDetailedViewController.m

-(void)showInformation { //you can omit the parameter, and do not forget to change the declaration in header file 
    NSString *informationType = @""; 
    switch (self.informationId) { 
    case 0: 
     self.title = @"About Us"; 
     informationType = KHABOUTUS; 
    break; 
    case 1: 
     self.title = @"Disclaimer"; 
     informationType = KHDISCLAIMER; 
    break; 
    default: 
    break; 
    } 

    NSURL *targetURL = [NSURL URLWithString:informationType]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL]; 
    [webInfoDetailed loadRequest:request]; 
} 

最後,更換呼籲showInformation方法

InformationViewController.m

 // About Us button clicked 
     -(void)aboutUsAction:(id)sender{ 
      [informationDetailedViewController setInformationId:0]; 
      [self.navigationController pushViewController:informationDetailedViewController animated:YES]; 
     } 

     // Terms and condition button clicked 
     -(void)termsAndConditionAction:(id)sender{ 
      [informationDetailedViewController setInformationId:1]; 
      [self.navigationController pushViewController:informationDetailedViewController animated:YES]; 
     } 

希望它能幫助。

相關問題