Hello,
I have recently started programming with xcode and my app launches fine in the simulator. The problem is I want to cover every movement combination of the Picker to produce different values in the label. Is it possible to do a sort of refresh on the picker after every movement so that each time it checks the 3 components after each movement?
I have recently started programming with xcode and my app launches fine in the simulator. The problem is I want to cover every movement combination of the Picker to produce different values in the label. Is it possible to do a sort of refresh on the picker after every movement so that each time it checks the 3 components after each movement?
Code:
//
// DoublePickerViewController.m
// DoublePicker
//
// Created by mac on 4/14/11.
// Copyright __MyCompanyName__ 2011. All rights reserved.
//
#import "DoublePickerViewController.h"
@implementation DoublePickerViewController
@synthesize doublePicker;
@synthesize osTypes;
@synthesize langTypes;
@synthesize threeTypes;
-(IBAction)buttonPressed
{
NSInteger langRow = [doublePicker selectedRowInComponent:
kLangComponent];
NSInteger osRow = [doublePicker selectedRowInComponent:
kOSComponent];
NSInteger threeRow = [doublePicker selectedRowInComponent:
kThreeComponent];
NSString *lang = [langTypes objectAtIndex:langRow];
NSString *os = [osTypes objectAtIndex:osRow];
NSString *three = [threeTypes objectAtIndex:threeRow];
NSString *message = [[NSString alloc] initWithFormat:
@"Your %@ on %@ on %@ language will be right up.",lang, os, three];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
@"Thank you for your choice"
message:message
delegate:nil
cancelButtonTitle:@"Great!"
otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
}
- (void)viewDidLoad {
NSArray *langArray = [[NSArray alloc] initWithObjects:
@"203x133", @"254x102", nil];
self.langTypes = langArray;
[langArray release];
NSArray *osArray = [[NSArray alloc] initWithObjects:
@"Beam Y-Y", @"Beam X-X", nil];
self.osTypes = osArray;
[osArray release];
NSArray *threeArray = [[NSArray alloc] initWithObjects:
@"22", @"25", nil];
self.threeTypes = threeArray;
[threeArray release];
}
- (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.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.doublePicker = nil;
self.langTypes = nil;
self.osTypes = nil;
self.threeTypes = nil;
[super viewDidUnload];
}
- (void)dealloc {
[doublePicker release];
[langTypes release];
[osTypes release];
[threeTypes release];
[super dealloc];
}
#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
if (component == kLangComponent)
return [self.langTypes count];
return [self.osTypes count];
return [self.threeTypes count];
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
if (component == kLangComponent)
return [self.langTypes objectAtIndex:row];
if (component == kOSComponent)
return [self.osTypes objectAtIndex:row];
if (component == kThreeComponent)
return [self.threeTypes objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component == 0,1,2 && row == 0)
{
pickLabel.text = @"1001";
}
{
if (component == 0,2 && row == 0, component == 1 && row == 1)
{
pickLabel.text = @"1002";
}
{
if (component == 0,1 && row == 0, component == 2 && row == 1)
{
pickLabel.text = @"1006";
}
{
if (component == 1,2 && row == 0, component == 0 && row == 1)
{
pickLabel.text = @"1026";
}
{
if (component == 1,2 && row == 1, component == 0 && row == 1)
{
pickLabel.text = @"1031";
}
}
}
}
}
}
@end
Last edited by a moderator: