NSWindowController 多个窗口之间传递值
来源:互联网 发布:ftp端口被使用不能上网 编辑:程序博客网 时间:2024/04/30 05:12
NSWindowController 多个窗口之间传递值
主界面一个按钮点击,出现另一个窗口,然后输入123,点OK,在主界面的编辑框内可以得到123这个值,
思路:
由于要给主界面的控件赋值,所以在第二个窗口里面设定一个同类型的变量。
然后主界面的控件 = 第二个窗口的同类型变量。
例如:主界面是
NSTextField 控件1,
那么就在子窗口里面设定这样一个变量(NSTextField a1),给值。
然后在主界面调用时,让主界面的NSTextField 控件1 =a1
这样主界面就可以得到子界面的值了。
子界面代码如下
H文件
//// Form1.h// test_multi_window//// Created by EDU on 3/6/14.// Copyright (c) 2014 EDU. All rights reserved.//#import <Cocoa/Cocoa.h>@interface Form1 : NSWindowController@property (assign) IBOutlet NSWindow *window_form1;@property (assign) NSInteger *button_ok_flag;@property (assign) NSString *button_string;@property (assign) IBOutlet NSTextField *m_Edit1;@property (assign) IBOutlet NSTextField *form_main;@property (assign) IBOutlet NSTextField *form_main_m_ET1;@property bool form_ok_cancel_result;-(void)get_value;@end
M文件
//// Form1.m// test_multi_window//// Created by on 3/6/14.// Copyright (c) 2014 EDU. All rights reserved.//#import "Form1.h"#import "EDUAppDelegate.h"@interface Form1 ()@end@implementation Form1@synthesize form_main;@synthesize form_main_m_ET1;@synthesize window_form1;@synthesize button_ok_flag;@synthesize button_string;@synthesize m_Edit1;@synthesize form_ok_cancel_result;- (id)initWithWindow:(NSWindow *)window{ NSLog (@"init()"); self = [super initWithWindow:window]; if (self) { } return self;}- (void)windowDidLoad{ [super windowDidLoad]; }- (IBAction)OnBT_OK:(id)sender{ form_main.stringValue = @"OK"; form_ok_cancel_result = true; [self get_value]; [super close];}- (IBAction)OnBT_Cancel:(id)sender{ form_main.stringValue = @"CANCEL"; form_ok_cancel_result = false; [self get_value]; [super close];}-(void)get_value{ form_main_m_ET1.stringValue = m_Edit1.stringValue;}@end
主窗口代码如下
H文件
//// EDUAppDelegate.h// test_multi_window//// Created by on 3/6/14.// Copyright (c) 2014 EDU. All rights reserved.//#import <Cocoa/Cocoa.h>#import "Form1.h"@interface EDUAppDelegate : NSObject <NSApplicationDelegate>@property (assign) Form1 *m_form1;@property (assign) IBOutlet NSWindow *window;@property (assign) IBOutlet NSTextField *m_label1;@property (assign) IBOutlet NSTextField *m_ET1;@end
M文件
//// EDUAppDelegate.m// test_multi_window//// Created by EDU on 3/6/14.// Copyright (c) 2014 EDU. All rights reserved.//#import "EDUAppDelegate.h"@implementation EDUAppDelegate@synthesize m_form1;@synthesize m_label1;@synthesize window;@synthesize m_ET1;- (void)dealloc{ [super dealloc];}- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{ // Insert code here to initialize your application}- (IBAction)OnBT_Form1:(id)sender{ if(!m_form1) { m_form1 = [[Form1 alloc] initWithWindowNibName:@"Form1"]; } m_form1.window.title = @"Hello,this is a test"; m_form1.form_main = m_label1; m_form1.form_main_m_ET1=m_ET1; [m_form1 showWindow: sender];}@end
运行编译OK
如图:
完成!
0 0
- NSWindowController 多个窗口之间传递值
- WPF--窗口之间的值传递
- PB窗口之间多参数的传递
- 窗口之间传递数据
- javascript中子窗口与父窗口之间的值传递
- 向窗口传递多个参数
- 向窗口传递多个参数
- PHP页面之间传递多个参数
- android之间传递多个对象
- 基于对话框的MFC窗口之间值的传递
- PB窗口之间传递多参数的方法
- PowerBuilder窗口之间传递多参数的方法
- PowerBuilder窗口之间传递多参数的方法
- PB窗口之间传递多参数的方法
- PowerBuilder窗口之间传递多参数的方法
- PB窗口之间传递多参数的方法
- PB窗口之间传递多参数的方法
- PB窗口之间传递多参数的方法
- SecureCRT颜色设置
- Javascript学习笔记十——网页运行原理
- Github 上关于 Switf 的 Flappy Bird Demo
- Android LayoutInflater
- INF文件的编写规则
- NSWindowController 多个窗口之间传递值
- web.xml 详解
- 运算器电路设计
- 一张帅图看清Java异常类的层次结构
- 验证74ls181逻辑功能
- 32bit存储器设计
- 乘法器
- php get_magic_quotes_gpc()…
- Javascript学习笔记十二——Ajax入门