简而言之,我的程序所做的是:它使用nswindow(由我的NSWindowController对象控制)定期执行并接受用户输入,并继续执行。可可:我有我的用户的输入 - 现在什么?
这里是我的myController.mm被调用和显示窗口取用户输入:
EncryptPasswordDlgController encPassController = [[EncryptPasswordDlgController alloc] init];
[encPassController showWindow:self];
NSString *inputPassword = [encPassController password];
这里是我的nswindowcontroller对象代码:
#import "EncryptPasswordDlgController.h"
@implementation EncryptPasswordDlgController
-(id) init
{
return self;
}
- (IBAction)showWindow:(id)sender
{
[super showWindow:sender];
encryptPasswordDlgWindowController = [[NSWindowController alloc] initWithWindowNibName:@"EncryptionPasswordDlg"];
[encryptPasswordDlgWindowController loadWindow];
[[self window] makeKeyAndOrderFront:[self window]];
return;
}
-(IBAction)clickOK:(id) sender
{
password = [passwordField stringValue];
NSLog(@"password is %@", password);
[[self window] close];
return;
}
-(NSString *)password
{
return password;
}
-(IBAction)clickCancel:(id) sender
{
// close the window
password = nil;
[[self window] close];
//return;
}
@end
后,我点击确定或取消按钮,相应的IBAction方法就会被调用并按要求执行,也就是说它显示的是从文本字段获取用户输入的窗口,点击确定后也会更新密码。但是在完成IBAction clickOK方法的执行后,它应该返回myController.mm并通过执行下一条语句“NSString * inputPassword = [encPassController password];”来检索密码这没有发生。请各位提出解决这种情况的方法。
编辑:
感谢鲍勃的答复。 我现在明白我的错误是什么。在我的节目中
while(isPasswordReceivedForEncryption == NO)
{
sleep(10000);
//continue;
}
,以便等到通知来并设置布尔变量设置为true: 所以我用while循环试图通知方法,如图所示。 但现在的问题是,它正在进入无限循环,我的应用正陷入困境。
有没有像MFC的等价物,它直接等待用户输入。 真的难以创建一个窗口并获得用户输入,或者我真的错过了这里的东西吗?
您已经在http://stackoverflow.com/questions/1337591/nswindowcontroller-program-execution上提出此问题。请尽量避免每次发布新问题;尽可能使用现有的线程。 – 2009-08-26 22:50:51