I am in the middle of trying to make one of my apps get set up to utilize pickers (UIPicker and UIDatePicker). However, I'm having a bit of trouble. When I run the app in the simulator, The result field does not display anything and XCode complains about Breakpoints. It is retrieving all the needed data, according to the information I get from Xcode (although I have not been something like NSLog to track it).
Here is the viewcontroller code:
here is the header file:
the two IBActions commented out have not been implemented yet, which is why they are commented out, but will eventually be dealt with.
here is the header file of the class where the variables are passed:
here is the implementation:
the prevDate class takes the year originally specified in the viewcontroller and decreases by one year and applies to the date of 12/31/(previous year of what was specified). All of this worked in Desktop versions of the app and it even worked in the iPhone simulator, when the UIPickerView was part of the user interface, instead of revealed by a button. So I don't get why the results will not display now.
highlighted code is in the ViewerController, not just the AppDelegate. Also, it even highlights in green the variable I use to retrieve the input from the textfield specifying year, which seems correct already. What is causing my application not to work?
Here is the viewcontroller code:
Code:
#import "RMD_CalculatorViewController.h"
#import "RMD.h"
@implementation RMD_CalculatorViewController
@synthesize picker;
@synthesize pickerArray;
@synthesize birth;
@synthesize bal;
@synthesize rmd;
@synthesize year;
@synthesize yt;
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (IBAction)displayYear
{
self.yt.hidden = NO;
self.picker.hidden = NO;
}
- (IBAction)setYear
{
NSInteger row = [picker selectedRowInComponent:0];
NSString* choice = [pickerArray objectAtIndex:row];
self.year.text = choice;
self.picker.hidden = YES;
self.yt.hidden = YES;
}
- (IBAction)calc:(id)sender
{
NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MM/dd/yyyy"];
RMD* retire = [[RMD alloc] init];
NSString* bd = self.birth.text;
NSString* syear = self.year.text;
double balance = self.bal.text.doubleValue;
[retire setBD:[df dateFromString:bd]];
[retire setBal:balance];
[retire setYear:[syear intValue]];
self.rmd.text = [NSString stringWithFormat:@"%.2f", [retire rmd]];
[df release];
[retire release];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSArray* array = [[NSArray alloc] initWithObjects:@"2011",@"2012",@"2013",@"2014",@"2015",@"2016",@"2017",@"2018",@"2019",nil];
self.pickerArray = array;
self.yt.hidden = YES;
self.picker.hidden = YES;
self.picker.delegate = self;
self.picker.dataSource = self;
[array release];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [pickerArray count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [pickerArray objectAtIndex:row];
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
here is the header file:
Code:
#import <UIKit/UIKit.h>
@interface RMD_CalculatorViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate>
{
IBOutlet UIPickerView* picker;
NSArray* pickerArray;
IBOutlet UITextField* birth;
IBOutlet UITextField* bal;
IBOutlet UITextField* rmd;
IBOutlet UITextField* year;
IBOutlet UIToolbar* yt;
}
@property (nonatomic, retain) UIPickerView* picker;
@property (nonatomic, retain) NSArray* pickerArray;
@property (nonatomic, retain) IBOutlet UITextField* birth;
@property (nonatomic, retain) IBOutlet UITextField* bal;
@property (nonatomic, retain) IBOutlet UITextField* rmd;
@property (nonatomic, retain) IBOutlet UITextField* year;
@property (nonatomic, retain) IBOutlet UIToolbar* yt;
- (IBAction)calc:(id)sender;
- (IBAction)displayYear;
/* - (IBAction)displayBirth; */
- (IBAction)setYear;
/* - (IBAction)setBirth; */
@end
the two IBActions commented out have not been implemented yet, which is why they are commented out, but will eventually be dealt with.
here is the header file of the class where the variables are passed:
Code:
#import <UIKit/UIKit.h>
/*
The RMD class contains methods to calculate RMD */
@interface RMD : NSObject
{
NSDate* bd;
double bal, rmd;
int year;
}
+ (RMD*) ret;
- (void)setBD:(NSDate*)b;
- (void)setBal:(double)c;
- (void)setYear:(int)y;
- (int)year;
- (NSDate*)bd;
- (int)age;
- (double)rmd;
@end
here is the implementation:
Code:
#import "RMD.h"
#import "prevDate.h"
@implementation RMD
- (id) init
{
if (self = [super init])
{
[self setBD:nil];
[self setBal:0];
[self setYear:0];
}
return self;
}
+ (RMD*) ret
{
RMD* newRMD = [[RMD alloc] init]; // create instance or RMD
return [newRMD autorelease]; // release object and free memory
}
- (void)setBD:(NSDate*)b
{
bd = b;
}
- (void)setBal:(double)c
{
bal = c;
}
- (void)setYear:(int)y
{
year = y;
}
- (int)year
{
return year;
}
- (NSDate*)bd
{
return bd;
}
- (int)age
{
prevDate* prev = [[prevDate alloc] init];
[prev setYear:[self year]];
[prev setMonth:12];
[prev setDay:31];
NSTimeInterval seconds = [[prev start] timeIntervalSinceDate:[self bd]];
int days = seconds/86400;
int age = days/365;
return age;
}
- (double)rmd
{
switch([self age])
{
case 70: rmd = bal/27.4; break;
case 71: rmd = bal/26.5; break;
case 72: rmd = bal/25.6; break;
case 73: rmd = bal/24.7; break;
case 74: rmd = bal/23.8; break;
case 75: rmd = bal/22.9; break;
case 76: rmd = bal/22.0; break;
case 77: rmd = bal/21.2; break;
case 78: rmd = bal/20.3; break;
case 79: rmd = bal/19.5; break;
case 80: rmd = bal/18.7; break;
case 81: rmd = bal/17.9; break;
case 82: rmd = bal/17.1; break;
case 83: rmd = bal/16.3; break;
case 84: rmd = bal/15.5; break;
case 85: rmd = bal/14.8; break;
case 86: rmd = bal/14.1; break;
case 87: rmd = bal/13.4; break;
case 88: rmd = bal/12.7; break;
case 89: rmd = bal/12.0; break;
case 90: rmd = bal/11.4; break;
case 91: rmd = bal/10.8; break;
case 92: rmd = bal/10.2; break;
case 93: rmd = bal/9.6; break;
case 94: rmd = bal/9.1; break;
case 95: rmd = bal/8.6; break;
case 96: rmd = bal/8.1; break;
case 97: rmd = bal/7.6; break;
case 98: rmd = bal/7.1; break;
case 99: rmd = bal/6.7; break;
case 100: rmd = bal/6.3; break;
case 101: rmd = bal/5.9; break;
case 102: rmd = bal/5.5; break;
case 103: rmd = bal/5.2; break;
case 104: rmd = bal/4.9; break;
case 105: rmd = bal/4.5; break;
case 106: rmd = bal/4.2; break;
case 107: rmd = bal/3.9; break;
case 108: rmd = bal/3.7; break;
case 109: rmd = bal/3.4; break;
case 110: rmd = bal/3.1; break;
case 111: rmd = bal/2.9; break;
case 112: rmd = bal/2.6; break;
case 113: rmd = bal/2.4; break;
case 114: rmd = bal/2.1; break;
default:
if([self age] >= 115)
{
rmd = bal/1.9;
}
else
{
rmd = 0.0;
}
break;
}
return rmd;
}
- (void) dealloc
{
[self setBD:nil];
[self setBal:0];
[self setYear:0];
[super dealloc]; // free memory
}
@end
the prevDate class takes the year originally specified in the viewcontroller and decreases by one year and applies to the date of 12/31/(previous year of what was specified). All of this worked in Desktop versions of the app and it even worked in the iPhone simulator, when the UIPickerView was part of the user interface, instead of revealed by a button. So I don't get why the results will not display now.
highlighted code is in the ViewerController, not just the AppDelegate. Also, it even highlights in green the variable I use to retrieve the input from the textfield specifying year, which seems correct already. What is causing my application not to work?
Last edited: