//
// AppDelegate.h
// osxApp
//
// Created by piao on 14-11-13.
// Copyright (c) 2014年 piao. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSButton *btnExit;
@property (weak) IBOutlet NSTextField *edtUserName;
@property (weak) IBOutlet NSTextField *edtSN;
@property (weak) IBOutlet NSButton *btnCalc;
- (IBAction)exit:(id)sender;
- (IBAction)calc:(id)sender;
@end
//
// AppDelegate.m
// osxApp
//
// Created by piao on 14-11-13.
// Copyright (c) 2014年 piao. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
- (void)alertDidEnd:(NSAlert *)alert
returnCode:(NSInteger)returnCode
contextInfo:(void *)contextInfo
{
switch (returnCode) {
case NSAlertFirstButtonReturn:
NSLog(@"NSAlertFirstButtonReturn");
exit(0); // 强制退出
break;
case NSAlertSecondButtonReturn:
NSLog(@"NSAlertSecondButtonReturn");
break;
default:
break;
}
}
- (IBAction)exit:(id)sender {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"确定"];
[alert addButtonWithTitle:@"取消"];
[alert setMessageText:@"友情提示"];
[alert setInformativeText:@"是否退出程序"];
[alert setAlertStyle:NSWarningAlertStyle];
//实现帮助主题按钮
//[alert setShowsHelp:YES];
//[alert setDelegate:self];
[alert beginSheetModalForWindow:_window modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
}
- (IBAction)calc:(id)sender {
// 从控件取值
NSString *userName = [[self edtUserName]stringValue];
// 写入到控件
[[self edtSN] setStringValue:userName];
}
@end
发表评论