值得一提的是,我對客觀的c和可可編程非常陌生,所以這可能是一個非常愚蠢的問題。好吧,我有窗口需要打開另一個窗口作爲模型表。我有以下文件:以編程方式關閉模態圖表目標C
- MainMenu.xib
- AppDelegate.m(方案顯然主窗口)(此手柄上的applicationDidFinishLaunching打開Login.xib)
- Login.xib(窗口即作爲模態片材,包含2個文本字段和一個按鈕)
- LoginController.m(該流程,在模態片填寫的數據)
AppDelegate.m:
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize loginScreen = _loginScreen;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Prompt user login credentials
[self activateLoginScreen];
}
-(IBAction)activateLoginScreen {
if (!_loginScreen)
[NSBundle loadNibNamed:@"Login" owner:self];
[NSApp beginSheet:self.loginScreen
modalForWindow:[[NSApp delegate] window]
modalDelegate:self
didEndSelector:NULL
contextInfo:NULL];
}
- (IBAction)closeLoginScreen:(id)sender {
[NSApp endSheet:self.loginScreen];
[self.loginScreen close];
self.loginScreen = nil;
}
我LoginController.m:
#import "LoginController.h"
@implementation LoginController
@synthesize txtMnemonic, txtPassword;
- (IBAction)btnLogin:(id)sender {
NSString *mnemonic = [txtMnemonic stringValue];
NSString *password = [txtPassword stringValue];
if ([mnemonic length] == 0 || [password length] == 0) {
NSLog(@"Please provide username and/or password.");
} else {
// Call web service here
}
}
@end
另外值得一提的是這裏是AppDelegate中的Login.xib文件所有者....
我的問題是,我可以打開模式窗口很好,當應用程序啓動。但是,我將如何從LoginController.m內關閉該窗口?這不能用一些按鈕操作來完成。該模式表單上的按鈕用於處理表單。因此,表單處理完畢並且所有內容都已經過驗證後,我是否願意關閉模式表單?所以基本上從LoginController.m中調用AppDelegate.m中的'closeLoginScreen()'
我希望所有這些都有意義,並且請只詢問是否需要進一步的信息。提前致謝!
忽略我的答案,認爲這是IOS – Fonix