从扩展程序打开应用程序,属性只改变第一次
问题描述:
我有一个今天的小部件扩展,当我点击一个按钮,它打开了应用程序。我第一次单击按钮并按照代码进行操作时,它会使用自定义URL方案来传递数据。这在AppDelegate中被解析,并且它计算出用什么数据填充ViewController
。 ViewController
使用故事板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];
}
答
这听起来像查看已经加载推部件基于控制器之前,所以弹出所有的视图控制器在handleOpenURL:函数中。
[self.viewController.navController popToRootViewControllerAnimated:NO];
if ([self.viewController presentedViewController]) {
[self.viewController dismissViewControllerAnimated:NO completion:nil];
}