diff --git a/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj b/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj index 9133b69179..b45e57dbd1 100644 --- a/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj +++ b/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj @@ -14,6 +14,8 @@ D531424E15BC87B6005EFF20 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D531424B15BC87B6005EFF20 /* main.m */; }; D531427215BC94B1005EFF20 /* backend.m in Sources */ = {isa = PBXBuildFile; fileRef = D531426F15BC94B1005EFF20 /* backend.m */; }; D531427415BC94B1005EFF20 /* system.m in Sources */ = {isa = PBXBuildFile; fileRef = D531427115BC94B1005EFF20 /* system.m */; }; + D5B6F94815FA8D4C0084A85B /* NRViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B6F94615FA8D4C0084A85B /* NRViewController.m */; }; + D5B6F94915FA8D4C0084A85B /* NRViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D5B6F94715FA8D4C0084A85B /* NRViewController.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,6 +34,9 @@ D531427115BC94B1005EFF20 /* system.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = system.m; path = build/nimcache/system.m; sourceTree = ""; }; D592E19015C7120F005258EA /* backend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = backend.h; path = build/nimcache/backend.h; sourceTree = ""; }; D592E19115C71415005258EA /* nimbase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = nimbase.h; path = build/nimcache/nimbase.h; sourceTree = ""; }; + D5B6F94515FA8D4C0084A85B /* NRViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NRViewController.h; path = src/NRViewController.h; sourceTree = ""; }; + D5B6F94615FA8D4C0084A85B /* NRViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NRViewController.m; path = src/NRViewController.m; sourceTree = ""; }; + D5B6F94715FA8D4C0084A85B /* NRViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = NRViewController.xib; path = src/NRViewController.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -99,8 +104,11 @@ children = ( D531424915BC87B6005EFF20 /* AppDelegate.h */, D531424A15BC87B6005EFF20 /* AppDelegate.m */, - D531424B15BC87B6005EFF20 /* main.m */, D531424C15BC87B6005EFF20 /* cross-calculator-Prefix.pch */, + D531424B15BC87B6005EFF20 /* main.m */, + D5B6F94515FA8D4C0084A85B /* NRViewController.h */, + D5B6F94615FA8D4C0084A85B /* NRViewController.m */, + D5B6F94715FA8D4C0084A85B /* NRViewController.xib */, ); name = src; sourceTree = ""; @@ -185,6 +193,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + D5B6F94915FA8D4C0084A85B /* NRViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -215,6 +224,7 @@ D531424E15BC87B6005EFF20 /* main.m in Sources */, D531427215BC94B1005EFF20 /* backend.m in Sources */, D531427415BC94B1005EFF20 /* system.m in Sources */, + D5B6F94815FA8D4C0084A85B /* NRViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/examples/cross_calculator/ios/src/AppDelegate.m b/examples/cross_calculator/ios/src/AppDelegate.m index d39a08b656..53e7f6188b 100644 --- a/examples/cross_calculator/ios/src/AppDelegate.m +++ b/examples/cross_calculator/ios/src/AppDelegate.m @@ -1,39 +1,39 @@ #import "AppDelegate.h" -#import "backend.h" +#import "NRViewController.h" + + +@interface AppDelegate () +@property (nonatomic, retain) NRViewController *viewController; +@end + @implementation AppDelegate +@synthesize viewController = _viewController; @synthesize window = _window; -- (void)dealloc -{ - [_window release]; - [super dealloc]; -} - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] - bounds]] autorelease]; - // Override point for customization after application launch. - self.window.backgroundColor = [UIColor whiteColor]; + self.window = [[[UIWindow alloc] + initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; + + self.viewController = [[NRViewController new] autorelease]; + if ([self.window respondsToSelector:@selector(setRootViewController:)]) + self.window.rootViewController = self.viewController; + else + [self.window addSubview:self.viewController.view]; [self.window makeKeyAndVisible]; - // Call nimrod code and store the result. - const int a = 3; - const int b = 12; - const int c = myAdd(a, b); - - // Add a label to show the results of the computation made by nimrod. - UILabel *label = [[UILabel alloc] initWithFrame:self.window.bounds]; - label.textAlignment = UITextAlignmentCenter; - label.text = [NSString stringWithFormat:@"myAdd(%d, %d) = %d", a, b, c]; - [self.window addSubview:label]; - [label release]; - return YES; } +- (void)dealloc +{ + [_window release]; + [_viewController release]; + [super dealloc]; +} + @end diff --git a/examples/cross_calculator/ios/src/NRViewController.h b/examples/cross_calculator/ios/src/NRViewController.h new file mode 100644 index 0000000000..36ba37758c --- /dev/null +++ b/examples/cross_calculator/ios/src/NRViewController.h @@ -0,0 +1,11 @@ +@interface NRViewController : UIViewController + +@property (nonatomic, retain) IBOutlet UIButton *calculateButton; +@property (nonatomic, retain) IBOutlet UITextField *aText; +@property (nonatomic, retain) IBOutlet UITextField *bText; +@property (nonatomic, retain) IBOutlet UILabel *resultLabel; + +- (IBAction)calculateButtonTouched; +- (IBAction)backgroundTouched; + +@end \ No newline at end of file diff --git a/examples/cross_calculator/ios/src/NRViewController.m b/examples/cross_calculator/ios/src/NRViewController.m new file mode 100644 index 0000000000..03b2548ad9 --- /dev/null +++ b/examples/cross_calculator/ios/src/NRViewController.m @@ -0,0 +1,74 @@ +#import "NRViewController.h" + +#import "backend.h" + + +@implementation NRViewController + +@synthesize aText = _aText; +@synthesize bText = _bText; +@synthesize calculateButton = _calculateButton; +@synthesize resultLabel = _resultLabel; + +/** We need no special custom initialization for this example. + * Note that this example project has been made to deploy only on iOS 4.x + * upwards because the currently available Xcode tools are incapable of + * generating iOS 3.x backwards compatible NIB files. If your device is 3.x + * only you can replace the NIM with UI construction in code and everything + * else should be fine. + */ +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)dealloc +{ + [_aText release]; + [_bText release]; + [_calculateButton release]; + [_resultLabel release]; + [super dealloc]; +} + +- (void)viewDidUnload +{ + self.calculateButton = nil; + self.aText = nil; + self.bText = nil; + self.resultLabel = nil; + [super viewDidUnload]; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation: + (UIInterfaceOrientation)interfaceOrientation +{ + return YES; +} + +/// User wants to calculate the inputs. Well, do it! +- (IBAction)calculateButtonTouched +{ + // Dismiss all keyboards. + [self backgroundTouched]; + + // Call nimrod code, store the result and display it. + const int a = [self.aText.text intValue]; + const int b = [self.bText.text intValue]; + const int c = myAdd(a, b); + self.resultLabel.text = [NSString stringWithFormat:@"%d + %d = %d", + a, b, c]; +} + +/// If the user touches the background, dismiss any visible keyboard. +- (IBAction)backgroundTouched +{ + [self.aText resignFirstResponder]; + [self.bText resignFirstResponder]; +} + +@end diff --git a/examples/cross_calculator/ios/src/NRViewController.xib b/examples/cross_calculator/ios/src/NRViewController.xib new file mode 100644 index 0000000000..3bf069b5ee --- /dev/null +++ b/examples/cross_calculator/ios/src/NRViewController.xib @@ -0,0 +1,507 @@ + + + + 0 + 11E53 + 2549 + 1138.47 + 569.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1498 + + + IBProxyObject + IBUIButton + IBUILabel + IBUITextField + IBUIView + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + + + 306 + {320, 34} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Nimrod Crossplatform Calculator + + 1 + MCAwIDAAA + + + 0 + 10 + 1 + + 2 + 18 + + + Helvetica-Bold + 18 + 16 + + + + + 294 + {{20, 42}, {165, 31}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Value A: + + + 0 + 10 + + 1 + 17 + + + Helvetica + 17 + 16 + + + + + 294 + {{20, 81}, {165, 31}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Value B: + + + 0 + 10 + + + + + + 291 + {{193, 124}, {107, 37}} + + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + Add! + + 3 + MQA + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + 3 + MC41AA + + + 2 + 15 + + + Helvetica-Bold + 15 + 16 + + + + + 292 + {{20, 124}, {60, 37}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + Result: + + + 0 + 10 + + + + + + 294 + {{88, 124}, {97, 37}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + + + + 0 + 10 + + + + + + 291 + {{193, 42}, {107, 31}} + + + + _NS:9 + NO + YES + IBCocoaTouchFramework + 0 + + 3 + Integer + + 3 + MAA + + 2 + + + 1 + YES + 17 + + 4 + IBCocoaTouchFramework + + 1 + + 1 + 14 + + + Helvetica + 14 + 16 + + + + + 291 + {{193, 81}, {107, 31}} + + + + _NS:9 + NO + YES + IBCocoaTouchFramework + 0 + + 3 + Integer + + 3 + MAA + + + 1 + YES + 17 + + 4 + IBCocoaTouchFramework + + 1 + + + + + {{0, 20}, {320, 460}} + + + + + 3 + MQA + + + + IBCocoaTouchFramework + + + + + + + view + + + + 3 + + + + resultLabel + + + + 15 + + + + calculateButton + + + + 16 + + + + aText + + + + 17 + + + + bText + + + + 18 + + + + backgroundTouched + + + 7 + + 20 + + + + calculateButtonTouched + + + 7 + + 21 + + + + + + 0 + + + + + + 1 + + + + + + + + + + + + + + + -1 + + + File's Owner + + + -2 + + + + + 4 + + + + + 7 + + + + + 8 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + 13 + + + + + 14 + + + + + + + NRViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIControl + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 21 + + + + + NRViewController + UIViewController + + id + id + + + + backgroundTouched + id + + + calculateButtonTouched + id + + + + UITextField + UITextField + UIButton + UILabel + + + + aText + UITextField + + + bText + UITextField + + + calculateButton + UIButton + + + resultLabel + UILabel + + + + IBProjectSource + ./Classes/NRViewController.h + + + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + 1498 + +