【发布时间】:2014-08-27 16:46:05
【问题描述】:
我正在开发一个需要用户输入代码的 iphone 应用程序。 我有一个第一个 viewController,当用户使用 -->
触摸按钮时,它将调用我的 passwordPrompt 视图控制器 [self performSegueWithIdentifier:@"passcodePrompt" sender:self];
密码提示显示正常,我可以输入我的密码,然后当我点击 ok 时,passwordPrompt 视图被关闭 -->
[self dismissViewControllerAnimated: YES completion:nil];
现在当我关闭这个视图控制器时,我从密码提示控制器调用我的 firstViewController 中的一个函数(我尝试使用 dismissViewControllerAnimated 的完成选项并尝试从 viewDidUnload 调用我的函数)-->
FirstViewController *firstViewControl = [[FirstViewController alloc] init];
[firstViewControl returnPass:[NSString stringWithFormat:@"%@%@%@%@",digit1.text,digit2.text,digit3.text,digit4.text]];
这个函数在我的 FirstViewController 中执行得很好,但即使它执行了那些代码行 -->
[passButton setTitle:@"Password is Correct" forState:UIControlStateNormal];
[(AppDelegate *)[[UIApplication sharedApplication] delegate] deactivateMoveDetection];
infoText.text = @"application unlocked until fully closed by user";
infoText.textColor = [UIColor blackColor];
passButton.tag = 0;
(调试显示它确实执行了这些行而没有任何错误,奇怪的是,在执行该函数后,调试器将我带回到在密码提示控制器中启动解除的函数)
标题没有改变,passButton.tag 没有设置为 0,infoText 没有改变,他的颜色也没有改变。
我一直在寻找 2 天没有运气。 感谢您的帮助
-----passcodePrompt.m -------
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = [[UIApplication sharedApplication]delegate];
dig1 = false;
dig2 = false;
dig3 = false;
dig4 = false;
ok.enabled = false;
// Do any additional setup after loading the view.
}
------- 解决方案 ------
我已添加到我的 passcodePrompt.h -->
@property (nonatomic, retain) FirstViewController *delegate;
为了能够使用 segueWithIdentifier 将 firstViewController 设置为我的密码提示的委托,我必须将其添加到我的 FirstViewcontroller.m -->
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
PasscodePrompt *passprompt = [segue destinationViewController];
passprompt.delegate = self;
}
从 passwordPrompt.m 中,我在 FirstViewController 中执行了我的函数 -->
[self.delegate returnPass:[NSString stringWithFormat:@"%@%@%@%@",digit1.text,digit2.text,digit3.text,digit4.text]];
【问题讨论】:
标签: ios objective-c iphone uiviewcontroller dismiss