2014-09-30 66 views
0

我有一個今天的小部件擴展,當我點擊一個按鈕,它打開了應用程序。我第一次單擊按鈕並按照代碼進行操作時,它會使用自定義URL方案來傳遞數據。這在AppDelegate中被解析,並且它計算出用什麼數據填充ViewControllerViewController使用故事板ID進行實例化。值將應用於其中一個ViewController的屬性,然後在viewDidLoad中,其餘值將基於Value中傳遞的值填充。這一切都是第一次。從擴展程序打開應用程序,屬性只改變第一次

但是,如果我點擊主頁按鈕,打開通知中心,在我的應用程序中點擊一個按鈕,然後再次瀏覽整個過程..我按正常方式瀏覽代碼,所有值都已設置,但當顯示ViewController時,值(如UILabel)與第一次相同,但它們應該已更改。

NSString *url = [NSString stringWithFormat:string ://%@", self.expanededTubeLine.lineName ]; 

NSExtensionContext *myExtension=[self extensionContext]; 
[myExtension openURL:[NSURL URLWithString:url] completionHandler:nil]; 

//

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { 

NSString *tubeLineName = [url host]; 

NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.koc.extensiontest"]; 

if ([defaults objectForKey:@"weekendData"]) { 

    NSData *tubeData = [[defaults objectForKey:@"weekendData"] copy]; 

    TFLParser *parser = [[TFLParser alloc] initWithData:tubeData]; 
    [parser parseData]; 
    for (int x = 0; x < parser.delayedTubeLines.count; x++) { 

     TubeLine *tl = [[TubeLine alloc] init]; 
     tl = [parser.delayedTubeLines objectAtIndex:x]; 
     if ([tl.lineName isEqualToString:tubeLineName]) { 

      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
      TubeLineViewController *tubeLineViewController = [storyboard instantiateViewControllerWithIdentifier:@"TubeLineViewController"]; 
      tubeLineViewController.tubeLine = tl; 


      [self.window.rootViewController presentViewController:tubeLineViewController animated:YES completion:nil]; 
      return YES; 
     } 
    } 
} 

}

//

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.tubeLineName.text = self.tubeLine.lineName; 
    self.tubeLineName.font = [UIFont openSansLightFontOfSize:18.0f]; 
    self.tubeLineName.textColor = [UIColor whiteColor]; 
    self.tubeLineName.backgroundColor = self.tubeLine.lineBackgroundUIColor; 
    self.tubeLineName.layer.cornerRadius = 5; 
    self.tubeLineName.clipsToBounds = YES; 

    self.tubeLineMessage.font = [UIFont openSansLightFontOfSize:18.0f]; 
    self.tubeLineMessage.text = self.tubeLine.lineMessage; 
    self.tubeLineMessage.textColor = [UIColor darkGrayColor]; 
} 

回答

3

這聽起來像查看已經加載推部件基於控制器之前,所以彈出所有的視圖控制器在handleOpenURL:函數中。

[self.viewController.navController popToRootViewControllerAnimated:NO]; 
    if ([self.viewController presentedViewController]) { 
     [self.viewController dismissViewControllerAnimated:NO completion:nil]; 
    } 
相關問題