Pergunta

I have this code that i did on Xcode 4.2 in a tabbed application and it works perfectly but what i would like it to be is a drop down menu in to a picker view but I'm not to sure what code i will need to add can you guys help heres my code

.h
#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController {

    IBOutlet UIPickerView *pickerView;
    NSMutableArray *list;
    IBOutlet UILabel *picklabel;
}

@end


.m

#import "FirstViewController.h"

@implementation FirstViewController

-(NSInteger)numberOfComponentsInPickerview:(UIPickerView *)thePickerView {
    return 1;
}



-(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
    return [list count];
}


-(NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { return [list objectAtIndex:row];

}

-(void)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row inComponent:(NSInteger)component {

    NSString *string = [NSString stringWithFormat:@"you selected: %@" , [list objectAtIndex:row]];
    picklabel.text = string;

}


- (void)viewDidUnload
{
    [super viewDidUnload];

    list = [[NSMutableArray alloc] init];
    [list addObject:@"Giraffe"];
    [list addObject:@"Water Bottle"];
    [list addObject:@"spinning Fan"];
    [list addObject:@"Hariy Monkey"];

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
Foi útil?

Solução

Follow this steps:

  • On selection of each pickerview, add that data to one mutable array
  • Each time reload your table view with that data (mutable array)
  • Selected data will get added to your tabular list.

Enjoy Coding :)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top