开发者

How to create a 3 component UIPickerView (TEMPLATES ANYONE???) iPhone

IPHONE problems ...I have tried several different templates and help from others, but I just can not seem to get this working, and it shouldn't be too difficult. I am wanting to add a UIPickerView with "3 Components" each are of numeric values (ex. they choose between 50-100 in each) and it shows what they selected in msg window. (The calculation part I will figure out later, but first I need to get the components registering the 3rd column properly, having problems after problems.... ANY IDEAS??

* I am not the most experienced, and heard that this was a great place to get answers from some very smart people. I truly appreciate any help or an outline "TEMPLATE" anyone could offer for a 3 component UIPickerView... THANKS IN ADVANCE>>> Lawrence

This is my ViewController.m code:

#import "DoubleComponentPickerViewController.h"

@implementation DoubleComponentPickerViewController

@synthesize doublePicker;
@synthesize oneTypes;
@synthesize twoTypes;
@synthesize threeTypes;


// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}


 -(IBAction)buttonPressed
{
    NSInteger oneRow = [doublePicker selectedRowInComponent:
                          kOneComponent];
    NSInteger twoRow = [doublePicker selectedRowInComponent:
                          kTwoComponent];
    NSInteger threeRow = [doublePicker selectedRowInComponent:
                          kThreeComponent];
    NSString *one = [oneTypes objectAtIndex:oneRow];
    NSString *two = [twoTypes objectAtIndex:twoRow];
    NSString *three = [threeTypes objectAtIndex:threeRow];

    NSString *message = [[NSString alloc] initWithFormat:
     @"First = %@         Second = %@          Third = %@",one, two, three];

    UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Please Confirm Numbers" message:message delegate:nil cancelButtonTitle:@"Confirm" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [message release];
}


/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    NSArray *oneArray = [[NSArray alloc] initWithObjects:
    @"91",@"92",@"93",@"94",@"95",@"96",nil];
    self.oneTypes = oneArray;
    [oneArray release];

    NSArray *twoArray = [[NSArray alloc] initWithObjects:
    @"97",@"98",@"99",@"100",@"101",@"102",@"103", nil];
    self.twoTypes = twoArray;
    [twoArray release];

    NSArray *threeArray = [[NSArray alloc] initWithObjects:
    @"102",@"103",@"104",@"105",@"106",@"107", nil];
    self.threeTypes = threeArray;
    [threeArray release];
    [super viewDidLoad];
}



// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarnin开发者_如何学JAVAg];

    // 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;
}


- (void)dealloc {
    [doublePicker release];
    [oneTypes release];
    [twoTypes release];
    [threeTypes release];
    [super dealloc];
}


 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  {
    return 3;
  }

 -(NSInteger)pickerView:(UIPickerView *)pickerView
   numberOfRowsInComponent:(NSInteger)component
  {
      if (component == kOneComponent)
        return[self.oneTypes count];
        return[self.twoTypes count];
        return[self.threeTypes count];

      if (component == kTwoComponent)
        return[self.oneTypes count];
        return[self.twoTypes count];
        return[self.threeTypes count];

      if (component == kThreeComponent)
        return[self.oneTypes count];
        return[self.twoTypes count];
        return[self.threeTypes count];
  }

 -(NSString *)pickerView:(UIPickerView *)pickerView
  titleForRow:(NSInteger)row
    forComponent:(NSInteger)component 
  {
    if (component == kThreeComponent)
    return [self. threeTypes objectAtIndex:row];
    return [self. twoTypes objectAtIndex:row];
    return [self. oneTypes objectAtIndex:row];

  }



@end


You can implement datasource methods

// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;

and then you can implement delegate method

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜