1
可以幫助澄清如何創建UIPickerView一旦按鈕被點擊?請給予幫助......非常感謝!點擊按鈕後如何創建UIPickerView?
其實,如下所示是代碼,我做什麼,一旦我點擊了按鈕選擇器視圖中顯示,但沒有任何數據,請找到下面的代碼: -
-(IBAction)buttonPressed1:(id)sender{
CGSize pickerSize = [myLocationPickerView sizeThatFits:CGSizeZero];
myLocationPickerView.frame = CGRectMake(0.0,250,pickerSize.width,pickerSize.height);
[self.view addSubview:myLocationPickerView];}
- (void)viewDidLoad {
[super viewDidLoad];
arrayNo = [[NSMutableArray alloc] init];
[arrayNo addObject:@" example 1 "];
[arrayNo addObject:@" example 2 "];
[arrayNo addObject:@" example 3 "];
[arrayNo addObject:@" example 4 "];
[myLocationPickerView selectRow:0 inComponent:0 animated:NO];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)myLocationPickerView;
{
return 1;
}
- (void)myLocationPickerView:(UIPickerView *)myLocationPickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
{
mlabel.text= [arrayNo objectAtIndex:row];
}
- (NSInteger)myLocationPickerView:(UIPickerView *)myLocationPickerView numberOfRowsInComponent:(NSInteger)component;
{
return [arrayNo count];
}
- (NSString *)myLocationPickerView:(UIPickerView *)myLocationPickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
return [arrayNo objectAtIndex:row];
}