UIPickerview in iphone

冷暖自知 提交于 2019-12-12 05:23:55

问题


How to place UIPickerView programmatically in a subView with out using Interface Builder?


回答1:


Hey! U can make UIPickerView programmatically....

In- viewController.m file

- (void)viewDidLoad {
    [super viewDidLoad];
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,100,320, 500)];
    [self.view addSubview:pickerView];
    [pickerView setDelegate:self];
        [pickerView release];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {

    return ; //give components here
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {

    return ;   //give rows here
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {   return ;  // give titles }

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    //Do the step here
}

And in your viewController.h class never forgot to do this

@interface viewController : UIViewController <UIPickerViewDelegate>

Hope this may help u.....for more help follow the link ..



来源:https://stackoverflow.com/questions/4559867/uipickerview-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!