按下按钮时弹出UIPickerview

时间:2012-03-05 19:46:08

标签: iphone

此代码有问题,因为当我按下按钮弹出UIPickerview时。什么都没发生。为什么会这样?

  -(void)pickerview:(id)sender
{
items =[[NSArray alloc]initWithObjects:@"Hindi",@"English",nil];

pickerView=[[UIPickerView alloc] initWithFrame:CGRectMake(10,100,150,150)];

pickerView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);

pickerView.delegate = self;

pickerView.dataSource = self;

pickerView.showsSelectionIndicator = YES;

pickerView.backgroundColor = [UIColor clearColor];

[pickerView selectRow:1 inComponent:0 animated:YES];

}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{

return 1;

}

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

return [items count];   
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{

return[items objectAtIndex:row];

}

有人可以告诉我这段代码有什么问题。

1 个答案:

答案 0 :(得分:6)

是的..大问题..

[self.view addSubview:pickerview]; 

缺少

你也确定按下按钮正在调用这个方法..返回(void)..如果连接到xib组件,它应该显示IBAction