使用 UIPickerview
我在 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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请按照以下步骤操作:
享受编码的乐趣:)
Follow this steps:
Enjoy Coding :)