gpt4 book ai didi

ios - 如何初始化另一个 View Controller 的值

转载 作者:行者123 更新时间:2023-11-29 03:23:41 24 4
gpt4 key购买 nike

在我的应用程序中,当用户从浏览器重定向到应用程序时,我会显示注册页面。因为我想从 url 变量中插入值。所以首先我从 url 获取值,然后显示带有文本框值的页面。但它没有设置文本框值。

我的代码:

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSString *urlString=[NSString stringWithContentsOfURL:url encoding:nil error:nil];
NSRange r = [urlString rangeOfString:@"gratzeez://" options:NSCaseInsensitiveSearch];

if(r.location != NSNotFound){
NSLog(@"founddddd");
NSLog(@"gratzeez url %@",url);
//NSString *str=[url valueForKey:@"email"];
NSArray *query = [[url query] componentsSeparatedByString:@"&"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithCapacity:[query count]];
for(NSString *parameter in query)
{
NSArray *kv = [parameter componentsSeparatedByString:@"="];
[parameters setObject:[kv count] > 1 ? [[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding] : [NSNull null]
forKey:[[kv objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding]];
}

NSLog(@"Parameters: %@", parameters);


[self.tabBar dismissViewControllerAnimated:NO completion:nil];
RegistrationViewController *RegistrationVC=[[RegistrationViewController alloc] initWithNibName:@"RegistrationViewController" bundle:nil];
RegistrationVC.txtEmail.userInteractionEnabled=NO;
NSLog(@"q = %@", [parameters objectForKey:@"email"]);

UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:RegistrationVC];
RegistrationVC.txtEmail.text=[parameters objectForKey:@"email"];
NSLog(@"value%@",RegistrationVC.txtEmail.text); //here getting null value
[self.tabBar presentViewController:navController animated:NO completion:nil];
navController.navigationItem.leftBarButtonItem=nil;
return YES;

}

我通过这种方式呈现 registrationviewcontroller 是什么?

RegistrationViewController *RegistrationVC=[[RegistrationViewController alloc] init ];

NSLog(@"q = %@", [parameters objectForKey:@"email"]);
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:RegistrationVC];

NSLog(@"txtemail %@ value%@",RegistrationVC.txtEmail,RegistrationVC.txtEmail.text);
[self.tabBar presentViewController:navController animated:NO completion:^{
RegistrationVC.txtEmail.userInteractionEnabled=NO;
RegistrationVC.txtEmail.text=[parameters objectForKey:@"email"];
}];

现在再次为两者提供 null。

最佳答案

正如我们在评论中看到的,当您尝试为其分配值时,不会创建您的 txtEmail。

我建议您向方法 presentViewController:animated:completion: 添加一个完成 block 。此时,您的 Controller RegistrationVC 将被加载并创建其 View (和 subview ),因此您将能够为您的元素分配值:

[self.tabBar presentViewController:navController animated:NO completion:^{
RegistrationVC.txtEmail.text=[parameters objectForKey:@"email"];
}];

关于ios - 如何初始化另一个 View Controller 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20757059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com