iPhon3-090222301@
simple calculator to my Love Mari composed by masa 20th Feb 2009
Calc23AppDelegate.h
//
#import
@class Calc23ViewController;
@interface Calc23AppDelegate : NSObject
UIWindow *window;
Calc23ViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet Calc23ViewController *viewController;
@end
Calc23AppDelegate.m
//
#import "Calc23AppDelegate.h"
#import "Calc23ViewController.h"
@implementation Calc23AppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
Calc23ViewController *aViewController = [[Calc23ViewController alloc]
initWithNibName:
@"Calc23ViewController" bundle:[NSBundle mainBundle]];
self.viewController = aViewController;
[aViewController release];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
UIView *controllersView = [viewController view];
[window addSubview:controllersView];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
Calc23ViewController.h
//
#import
@class UIAlertView;
@interface Calc23ViewController : UIViewController
IBOutlet UITextField *field1;
IBOutlet UITextField *field2;
IBOutlet UILabel *label1;
IBOutlet UIAlertView *baseAlert;
IBOutlet UIAlertView *alertView;
// NSInteger *firstOtherButtonIndex;
NSInteger *buttonIndex;
double a,b,c;// as global variable
}
@property (nonatomic, retain) UITextField *field1;
@property (nonatomic, retain) UITextField *field2;
@property (nonatomic, retain) UILabel *label1;
@property (nonatomic,retain) UIAlertView *baseAlert;
@property (nonatomic,retain) UIAlertView *alertView;
//@property (nonatomic,readonly) NSInteger *firstOtherButtonIndex;
@property (nonatomic, readonly) NSInteger *buttonIndex;
-(IBAction) Multiply:(id)sender;
@end
Calc23ViewController.m
//
#import "Calc23ViewController.h"
@implementation Calc23ViewController
@synthesize field1;
@synthesize field2;
@synthesize label1;
@synthesize baseAlert;
@synthesize alertView;
- (IBAction) Multiply:(id)sender {
//////////////////// input part ///////////
[field1 resignFirstResponder];
[field2 resignFirstResponder];
a = [[field1 text] doubleValue];
b = [[field2 text] doubleValue];
////////////////////////// alert part ////////////
UIAlertView *baseAlert = [[UIAlertView alloc]
initWithTitle:@""
message:@""
delegate:self cancelButtonTitle:nil
otherButtonTitles:@"x", @"/" ,@"+", @"-",@"BMI",@"eGFR(male)" ,
@"eGFR(female)",nil];
[baseAlert setNumberOfRows:6];
[baseAlert show];
}
//////////////////////////////////
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger) buttonIndex {
// [field1 setText:[NSString stringWithFormat:@"%d" ,buttonIndex]]; //as a checker of button number
switch (buttonIndex) {
case 0:
c = a * b;
break;
case 1:
c = a / b;
break;
case 2:
c = a + b;
break;
case 3:
c = a - b;
break;
case 4:
c = (a / (b*b)) *10;
break;
case 5:
c = 194*(pow(a,-0.287))*(pow(b,-1.094));
break;
case 6:
c = 0.739*194*(pow(a,-0.287))*(pow(b,-1.094));
break;
default:
break;
}
[label1 setText:[NSString stringWithFormat:@"result->%3.1f" ,c]];
}
- (void)dealloc {
/* To adhere to memory management rules, release the instance variables.'textField'
and 'label' are objects in the nib file and are created when the nib is loaded.)*/
[field1 release];
[field2 release];
[label1 release];
[super dealloc];
}
@end
あとは、Interface Builderを活用して hoge*.xib(mainではなく)を変えていく。hoge.pngを追加するときは、SDKからクリックして、main.xibのinspectorでhoge.pngを選択して、main.xibに移動しておいて、あとはそれをdragして、hoge.xibにうつす。この時textfieldなどがすでにあるので、上のbarから、後面に移動を選択すればよい。Emaの舞子さんを入れたら怪しいぐらいに完成したが、実際の掲示はやはり心配か。