I am using a UIPickerView and currently their is only a single object in it. How can I display that single object on label. It has this weird property that when we use pickerView the data is not set selected by default.Once we choose another object or roll it, then only any particular object is selected. Hence if only one object is their in pickerView. It does not count as selected even though when you tap on that single object. I tried a lot but found that if their are more than one object then only you can display the selected object on label but not if their is only one object.
问问题
192 次
1 回答
2
您需要编写一个在 UIPickerView 更改时触发的代码,如下所示:
#pragma
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
//Action that triggers following code:
{
NSString *nameString = [nameOnMutubaleArrayYouWannaGetDataFrom objectAtIndex:[picker selectedRowInComponent:0]]; //Or 1 if u have multiple rows
NSString *labelString = [[NSString alloc]initWithFormat:
@" %@ ", nameString];
labelOutput.text = labelString;
希望这可以帮助。
于 2012-11-09T10:59:44.953 回答