The Simplest App on MAC OSX
来源:互联网 发布:caffe 图像分割代码 编辑:程序博客网 时间:2024/05/16 03:22
Header:
//// myThirdTestAppAppDelegate.h// myThirdTestApp//// Created by solaris_navi on 10/25/11.// Copyright 2011 __MyCompanyName__. All rights reserved.//#import <Cocoa/Cocoa.h>@interface myThirdTestAppAppDelegate : NSObject <NSApplicationDelegate> { NSWindow *window; NSTextField *op1; NSTextField *op2; NSTextField *answerField;}@property (assign) IBOutlet NSWindow *window;// get value from interface@property (assign) IBOutlet NSTextField *op1;@property (assign) IBOutlet NSTextField *op2;@property (assign) IBOutlet NSTextField *answerField;// action- (IBAction)addOp1AndOp2:(id)sender;@end
Function
//// myThirdTestAppAppDelegate.m// myThirdTestApp//// Created by solaris_navi on 10/25/11.// Copyright 2011 __MyCompanyName__. All rights reserved.//#import "myThirdTestAppAppDelegate.h"@implementation myThirdTestAppAppDelegate@synthesize window;@synthesize op1;@synthesize op2;@synthesize answerField;- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{ // Insert code here to initialize your application}- (IBAction)addOp1AndOp2:(id)sender { float value1 = [self.op1 floatValue]; float value2 = [self.op2 floatValue]; float valueAnswer = value1 + value2; [self.answerField setFloatValue:valueAnswer];}@end
What's the difficulties?
so basically, you have to understand how the messages will be send from view to controller. objective C Cocoa Applications use MVC framework, but unlike Java Applications, they will exchange messages instead of sending value directly from one object to another.
in this example,
in the header file, we defined 2 outlets which connect to 2 textFields as operators and 1 label as answer field, and 1 action on the button which would be implemented an Add function(value1, value2) then sent the result back.
then, in the function file, in the action field of button, firstly, we ask for the value of 2 operators, therefore we send messages which look like [self.op1 floatValue]. floatValue/StringValue/doubleValue are built-in in the IDE, so we don't have to predefine them. finally, After applying the add function, we send message to answerField in self and tell it setFloatValue = the answer.
what's more, if we define a class, we can create a property (member of class) in the class then use synthesize property to create get/set function (which is rather close to the way in VS.net, but maybe also accessible in Java although I don't think so).
after creating a class, don't forget to synthesize property after create an object from the class. The class is in the self container as well.
summarize all, it is hard to program in Mac OSX unless you got the idea of message-built-in object-oriented programming. but i think it is only a matter of time.. practice!
- The Simplest App on MAC OSX
- Install plantuml on Mac OSX
- Install liblinear on Mac OSX
- Install mpv on Mac OSX
- Install ideviceinstaller on Mac OSX
- Install ideviceinstaller on Mac OSX
- Install upx on Mac OSX
- Install socat on Mac OSX
- Clicking the dock icon to show the app on Mac
- The simplest Singleton
- The Simplest View Controller
- qmake for simple makefile on mac osx
- How to install YAWS on Mac OSX
- Qt for Android on Mac OSX部署
- Installing libevent on MAC OSX 10.6
- Raspberry Pi -- Cross Compiling on Mac OSX
- How to install Maven on Mac OSX
- OpenCV on Mac OSX 安装详解
- IE9 didn't show the canvas
- 鸟哥P160练习答案
- linux学习材料记录
- 如何进入linux 单用户模式维护
- C#特性学习与使用(为枚举定义Description)
- The Simplest App on MAC OSX
- 怎样使用Eclipse来开发Android源码
- 用JAVA多线程编程解决Lamport's Bakery问题
- IDA 封面人物 Ada Lovelace
- SQLserverAgent无法启动的解决方法
- 分享Silverlight/WPF/Windows Phone一周学习导读(10月16日-10月22日)
- implement a queue by using two stacks [No. 31]
- aspnetdb.mdf数据字典
- 横空出世,席卷互联网--评微软等公司数据结构和算法面试100题