我有这个代码,我在 Xcode 4.2 的选项卡式应用程序中执行,它运行良好,但我希望它是一个下拉菜单进入选择器视图,但我不确定我需要添加什么代码你们能帮我的代码吗
.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;
}