Hello all...
I am a noob at programming but I am making some headway so... thank you in advance for any help you may choose to give. I am building an app that displays a 3 column picker. The words in the array are long, so I am trying to resize the fonts. I found a method I am trying to implement, but when I insert it into my code, my wheels come up blank. I know that this is a noob issue. But have yet to find a solution.
Here is my code...
DoubleComponentPickerViewController.h
DoubleComponentPickerViewController.m
Thank you again for your help...
(please be kind to the noob...
I am a noob at programming but I am making some headway so... thank you in advance for any help you may choose to give. I am building an app that displays a 3 column picker. The words in the array are long, so I am trying to resize the fonts. I found a method I am trying to implement, but when I insert it into my code, my wheels come up blank. I know that this is a noob issue. But have yet to find a solution.
Here is my code...
DoubleComponentPickerViewController.h
Code:
#import <UIKit/UIKit.h>
#define kfirstComponent 0
#define kmiddleComponent 1
#define klastComponent 2
@interface DoubleComponentPickerViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource>
{
IBOutlet UIPickerView *doublePicker;
NSArray *firstTypes;
NSArray *middleTypes;
NSArray *lastTypes;
}
@property (nonatomic,retain) UIPickerView *doublePicker;
@property (nonatomic,retain) NSArray *firstTypes;
@property (nonatomic,retain) NSArray *middleTypes;
@property (nonatomic,retain) NSArray *lastTypes;
-(IBAction)buttonPressed;
@end
DoubleComponentPickerViewController.m
Code:
#import "DoubleComponentPickerViewController.h"
@implementation DoubleComponentPickerViewController
@synthesize doublePicker;
@synthesize firstTypes;
@synthesize middleTypes;
@synthesize lastTypes;
-(IBAction)buttonPressed
{
NSInteger firstRow = [doublePicker selectedRowInComponent:kfirstComponent];
NSInteger middleRow = [doublePicker selectedRowInComponent:kmiddleComponent];
NSInteger lastRow = [doublePicker selectedRowInComponent:klastComponent];
NSString *first = [firstTypes objectAtIndex:firstRow];
NSString *middle = [middleTypes objectAtIndex:middleRow];
NSString *last = [lastTypes objectAtIndex:lastRow];
NSString *message = [[NSString alloc] initWithFormat:@"%@ %@ %@ Warning.",first, middle, last];
UIAlertView *alert = [[ UIAlertView alloc] initWithTitle:@"Description:"
message:message
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
}
- (void)viewDidLoad
{
NSArray *firstArray = [[NSArray alloc] initWithObjects:
@"sample1a",@"sample2a",@"sample3a",nil];
self.firstTypes = firstArray;
[firstArray release];
NSArray *middleArray = [[NSArray alloc] initWithObjects:
@"sample1b",@"sample2b",@"sample3b",nil];
self.middleTypes = middleArray;
[middleArray release];
NSArray *lastArray = [[NSArray alloc] initWithObjects:
@"sample1c",@"sample2c",@"sample3c",nil];
self.lastTypes = lastArray;
[lastArray release];
[super viewDidLoad];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
/* Ugly attempt at sizing font */
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *pickerLabel = (UILabel *)view;
// Reuse the label if possible, otherwise create and configure a new one
if ((pickerLabel == nil) || ([pickerLabel class] != [UILabel class]))
{ //newlabel
CGRect frame = CGRectMake(0.0, 0.0, 270, 32.0);
pickerLabel = [[[UILabel alloc] initWithFrame:frame] autorelease];
pickerLabel.textAlignment = UITextAlignmentLeft;
pickerLabel.backgroundColor = [UIColor clearColor];
pickerLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:8];
}
pickerLabel.textColor = [UIColor blackColor];
return pickerLabel;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component == 0)
{
return [self.firstTypes count];
}
if (component == 1)
{
return [self.middleTypes count];
}
else
{
return [self.lastTypes count];
}
}
-(NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component == 0)
{
return [self.firstTypes objectAtIndex:row];
}
if (component == 1)
{
return [self.middleTypes objectAtIndex:row];
}
else
{
return [self.lastTypes objectAtIndex:row];
}
/*if (component == kfirstComponent)
return [self.firstTypes objectAtIndex:row];
return [self.middleTypes objectAtIndex:row];
return [self.lastTypes objectAtIndex:row];
*/
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload
{
}
- (void)dealloc
{
[super dealloc];
}
@end
Thank you again for your help...
(please be kind to the noob...