From b1ad04e30654264da13d84038dc24b551b619604 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Sat, 8 Sep 2012 11:26:04 +0200 Subject: [PATCH] Changes NIB to template and generates code manually for UI. --- .../project.pbxproj | 14 +- .../ui}/NRViewController.xib | 196 ++++++++---------- .../ios/src/NRViewController.m | 168 +++++++++++++-- 3 files changed, 246 insertions(+), 132 deletions(-) rename examples/cross_calculator/ios/{src => resources/ui}/NRViewController.xib (87%) diff --git a/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj b/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj index b45e57dbd1..36b43d31bf 100644 --- a/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj +++ b/examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ 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 */ @@ -36,7 +35,7 @@ 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 = ""; }; + D5B6F96315FB448D0084A85B /* NRViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = NRViewController.xib; path = resources/ui/NRViewController.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -87,6 +86,7 @@ isa = PBXGroup; children = ( D531424615BC8756005EFF20 /* plist */, + D5B6F96115FB447C0084A85B /* ui */, ); name = resources; sourceTree = ""; @@ -108,7 +108,6 @@ D531424B15BC87B6005EFF20 /* main.m */, D5B6F94515FA8D4C0084A85B /* NRViewController.h */, D5B6F94615FA8D4C0084A85B /* NRViewController.m */, - D5B6F94715FA8D4C0084A85B /* NRViewController.xib */, ); name = src; sourceTree = ""; @@ -141,6 +140,14 @@ name = nimrod; sourceTree = ""; }; + D5B6F96115FB447C0084A85B /* ui */ = { + isa = PBXGroup; + children = ( + D5B6F96315FB448D0084A85B /* NRViewController.xib */, + ); + name = ui; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -193,7 +200,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - D5B6F94915FA8D4C0084A85B /* NRViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/examples/cross_calculator/ios/src/NRViewController.xib b/examples/cross_calculator/ios/resources/ui/NRViewController.xib similarity index 87% rename from examples/cross_calculator/ios/src/NRViewController.xib rename to examples/cross_calculator/ios/resources/ui/NRViewController.xib index 3bf069b5ee..b260db2afc 100644 --- a/examples/cross_calculator/ios/src/NRViewController.xib +++ b/examples/cross_calculator/ios/resources/ui/NRViewController.xib @@ -37,6 +37,40 @@ 274 + + + 292 + {{0, -10}, {320, 480}} + + + _NS:9 + NO + 1 + IBCocoaTouchFramework + 0 + 0 + + 3 + MQA + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + 3 + MC41AA + + + 2 + 15 + + + Helvetica-Bold + 15 + 16 + + 306 @@ -48,6 +82,7 @@ NO YES 7 + 2 NO IBCocoaTouchFramework Nimrod Crossplatform Calculator @@ -80,6 +115,7 @@ NO YES 7 + 3 NO IBCocoaTouchFramework Value A: @@ -108,6 +144,7 @@ NO YES 7 + 4 NO IBCocoaTouchFramework Value B: @@ -127,32 +164,20 @@ _NS:9 NO + 5 IBCocoaTouchFramework 0 0 1 Add! - - 3 - MQA - + 1 MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - - 3 - MC41AA - - - 2 - 15 - - - Helvetica-Bold - 15 - 16 - + + + @@ -165,6 +190,7 @@ NO YES 7 + 6 NO IBCocoaTouchFramework Result: @@ -186,6 +212,7 @@ NO YES 7 + 7 NO IBCocoaTouchFramework @@ -206,6 +233,7 @@ _NS:9 NO YES + 8 IBCocoaTouchFramework 0 @@ -246,6 +274,7 @@ _NS:9 NO YES + 9 IBCocoaTouchFramework 0 @@ -282,66 +311,7 @@ - - - - view - - - - 3 - - - - resultLabel - - - - 15 - - - - calculateButton - - - - 16 - - - - aText - - - - 17 - - - - bText - - - - 18 - - - - backgroundTouched - - - 7 - - 20 - - - - calculateButtonTouched - - - 7 - - 21 - - + @@ -362,6 +332,7 @@ + @@ -377,33 +348,8 @@ - 4 - - - - - 7 - - - - - 8 - - - - - 10 - - - - - 11 - - - - - 12 - + 14 + @@ -412,8 +358,38 @@ - 14 - + 12 + + + + + 11 + + + + + 10 + + + + + 8 + + + + + 7 + + + + + 4 + + + + + 22 + @@ -423,13 +399,13 @@ 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 com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -438,7 +414,7 @@ - 21 + 22 @@ -496,10 +472,6 @@ com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - - com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - - YES 3 1498 diff --git a/examples/cross_calculator/ios/src/NRViewController.m b/examples/cross_calculator/ios/src/NRViewController.m index 03b2548ad9..bd0df7d6bd 100644 --- a/examples/cross_calculator/ios/src/NRViewController.m +++ b/examples/cross_calculator/ios/src/NRViewController.m @@ -10,22 +10,6 @@ @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]; @@ -71,4 +55,156 @@ [self.bText resignFirstResponder]; } +/** Custom loadView method for backwards compatiblity. + * Unfortunately I've been unable to coerce Xcode 4.4 to generate nib files + * which are compatible with my trusty iOS 3.0 ipod touch so in order to be + * fully compatible for all devices we have to build the interface manually in + * code rather than through the keyed archivers provided by the interface + * builder. + * + * Rather than recreating the user interface manually in code the tool nib2obj + * was used on the xib file and slightly modified to fit the original property + * names. Which means here is a lot of garbage you would never write in real + * life. Please ignore the following "wall of code" for the purposes of + * learning Nimrod, this is all just because Apple can't be bothered to + * maintain backwards compatibility properly. + */ +- (void)loadView +{ + [super loadView]; + + self.calculateButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + self.calculateButton.autoresizesSubviews = YES; + self.calculateButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; + self.calculateButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; + self.calculateButton.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.calculateButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + self.calculateButton.frame = CGRectMake(193.0, 124.0, 107.0, 37.0); + self.calculateButton.tag = 5; + [self.calculateButton setTitle:@"Add!" forState:UIControlStateNormal]; + [self.calculateButton addTarget:self + action:@selector(calculateButtonTouched) + forControlEvents:UIControlEventTouchUpInside]; + + UILabel *label11 = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 124.0, 60.0, 37.0)]; + label11.adjustsFontSizeToFitWidth = YES; + label11.autoresizesSubviews = YES; + label11.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + label11.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + label11.frame = CGRectMake(20.0, 124.0, 60.0, 37.0); + label11.tag = 6; + label11.text = @"Result:"; + + UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 34.0)]; + label4.adjustsFontSizeToFitWidth = YES; + label4.autoresizesSubviews = YES; + label4.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin; + label4.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + label4.frame = CGRectMake(0.0, 0.0, 320.0, 34.0); + label4.tag = 2; + label4.text = @"Nimrod Crossplatform Calculator"; + label4.textAlignment = UITextAlignmentCenter; + + UIButton *background_button = [UIButton buttonWithType:UIButtonTypeCustom]; + background_button.autoresizesSubviews = YES; + background_button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + background_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; + background_button.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + background_button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + background_button.frame = CGRectMake(0.0, -10.0, 320.0, 480.0); + background_button.tag = 1; + [background_button addTarget:self action:@selector(backgroundTouched) + forControlEvents:UIControlEventTouchDown]; + + self.resultLabel = [[[UILabel alloc] initWithFrame:CGRectMake(88.0, 124.0, 97.0, 37.0)] autorelease]; + self.resultLabel.adjustsFontSizeToFitWidth = YES; + self.resultLabel.autoresizesSubviews = YES; + self.resultLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + self.resultLabel.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.resultLabel.frame = CGRectMake(88.0, 124.0, 97.0, 37.0); + self.resultLabel.tag = 7; + self.resultLabel.text = @""; + + self.aText = [[[UITextField alloc] initWithFrame:CGRectMake(193.0, 42.0, 107.0, 31.0)] autorelease]; + self.aText.adjustsFontSizeToFitWidth = YES; + self.aText.autocapitalizationType = UITextAutocapitalizationTypeNone; + self.aText.autocorrectionType = UITextAutocorrectionTypeDefault; + self.aText.autoresizesSubviews = YES; + self.aText.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; + self.aText.borderStyle = UITextBorderStyleRoundedRect; + self.aText.clearButtonMode = UITextFieldViewModeWhileEditing; + self.aText.clearsOnBeginEditing = NO; + self.aText.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + self.aText.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.aText.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + self.aText.enablesReturnKeyAutomatically = NO; + self.aText.frame = CGRectMake(193.0, 42.0, 107.0, 31.0); + self.aText.keyboardAppearance = UIKeyboardAppearanceDefault; + self.aText.keyboardType = UIKeyboardTypeNumberPad; + self.aText.placeholder = @"Integer"; + self.aText.returnKeyType = UIReturnKeyDefault; + self.aText.tag = 8; + self.aText.text = @""; + self.aText.textAlignment = UITextAlignmentCenter; + + UILabel *label7 = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 42.0, 165.0, 31.0)]; + label7.adjustsFontSizeToFitWidth = YES; + label7.autoresizesSubviews = YES; + label7.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + label7.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + label7.frame = CGRectMake(20.0, 42.0, 165.0, 31.0); + label7.tag = 3; + label7.text = @"Value A:"; + + UILabel *label8 = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 81.0, 165.0, 31.0)]; + label8.adjustsFontSizeToFitWidth = YES; + label8.autoresizesSubviews = YES; + label8.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + label8.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + label8.frame = CGRectMake(20.0, 81.0, 165.0, 31.0); + label8.tag = 4; + label8.text = @"Value B:"; + + self.bText = [[[UITextField alloc] + initWithFrame:CGRectMake(193.0, 81.0, 107.0, 31.0)] autorelease]; + self.bText.adjustsFontSizeToFitWidth = YES; + self.bText.autocapitalizationType = UITextAutocapitalizationTypeNone; + self.bText.autocorrectionType = UITextAutocorrectionTypeDefault; + self.bText.autoresizesSubviews = YES; + self.bText.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; + self.bText.borderStyle = UITextBorderStyleRoundedRect; + self.bText.clearButtonMode = UITextFieldViewModeWhileEditing; + self.bText.clearsOnBeginEditing = NO; + self.bText.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + self.bText.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.bText.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + self.bText.enablesReturnKeyAutomatically = NO; + self.bText.frame = CGRectMake(193.0, 81.0, 107.0, 31.0); + self.bText.keyboardAppearance = UIKeyboardAppearanceDefault; + self.bText.keyboardType = UIKeyboardTypeNumberPad; + self.bText.placeholder = @"Integer"; + self.bText.returnKeyType = UIReturnKeyDefault; + self.bText.tag = 9; + self.bText.text = @""; + self.bText.textAlignment = UITextAlignmentCenter; + + self.view.frame = CGRectMake(0.0, 20.0, 320.0, 460.0); + self.view.autoresizesSubviews = YES; + self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.view.backgroundColor = [UIColor colorWithWhite:1.000 alpha:1.000]; + self.view.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.view.frame = CGRectMake(0.0, 20.0, 320.0, 460.0); + self.view.tag = 0; + + [self.view addSubview:background_button]; + [self.view addSubview:label4]; + [self.view addSubview:label7]; + [self.view addSubview:label8]; + [self.view addSubview:self.calculateButton]; + [self.view addSubview:label11]; + [self.view addSubview:self.resultLabel]; + [self.view addSubview:self.aText]; + [self.view addSubview:self.bText]; +} + @end