gpt4 book ai didi

objective-c - 在applicationDidBecomeActive中调用NSRunLoop方法导致系统无响应

转载 作者:行者123 更新时间:2023-11-29 04:57:42 29 4
gpt4 key购买 nike

当我的 iOS 应用程序被激活时,单击应用程序支持的文件 (FTA) 时,我想在 applicationDidBecomeActive 中显示模态视图。因为我想要回控制权,所以当模态视图被关闭时,我使用 NSRunLoop 和一个标志来检测 View 是否被关闭。请参阅随附的代码。当调用 [NSRunloop runUntilDate] 时,我的 View 会显示,但位于当前 View 后面,并且不响应键盘/鼠标操作。任何想法发生了什么。

[代码]

- (void) applicationDidBecomeActive:(UIApplication *)application {


//App activated due to file selection in an email attachment, display modal dialog
if (fileSelected)
{
RSAImportViewController *s = [[RSAImportViewController alloc] initWithNibName:@"RSAImportViewController_iPad" bundle:nil];

UINavigationController* rNC = [[UINavigationController alloc] initWithRootViewController:s];

[rNC setModalPresentationStyle:UIModalPresentationFormSheet];
[rNC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];

[nav presentModalViewController:rNC animated:YES];

// wait for modal view to be dismissed, the modal view is dismissed when ok/cancel
// buttons are clicked.

while (s.completion == requestRunning) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
}

[s dismissKeyboard];

// Do further processing

return;
}

最佳答案

这不是 NSRunLoop 方法的用途。

您应该将自己设置为模态视图的委托(delegate),并让模态视图在其委托(delegate)被解除时通知其委托(delegate),并根据需要调用任何其他方法来执行您想做的任何事情。

在 RSAImportViewController.h 中:

@class RSAImportViewController
@protocol RSAImportViewControllerDelegate
-(void)rsaImportViewControllerDone:(RSAImportViewController*)vc;
@end

@interface RSAImportViewController
...
@property(assign) id<RSAImportViewControllerDelegate> delegate;
@end

在 RSAImportViewController.m 中,无论您在何处调用 dismissModalViewControllerAnimated: 方法:

@implementation RSAImportViewController
@synthesize delegate;
...
-(void)someMethodInYourCode {
...
[self dismissModalViewControllerAnimated:YES];
// call the delegate method to inform we are done (adapt to your needs)
[self.delegate rsaImportViewControllerDone:self];
}
...
@end

在 AppDelegate 中:

- (void) applicationDidBecomeActive:(UIApplication *)application {
{
if (fileSelected) {
...
rNC.delegate = self; // set 'self' to be informed when the rNC is dismissed
[nav presentModalViewController:rNC animated:YES];
} else {
[self doFurtherProcessing];
}
}
-(void)rsaImportViewControllerDone:(RSAImportViewController*)vc {
[self doFurtherProcessing];
}
-(void)doFurtherProcessing {
[s dismissKeyboard];
// and all your other stuff
}

关于objective-c - 在applicationDidBecomeActive中调用NSRunLoop方法导致系统无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7621444/

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