简体   繁体   English

在单个选择器中选择的项目为null

[英]selected Item in single picker is null

I have single picker when the user select type it will update label but when I select item it equal null to label 我有一个选择器,当用户选择类型时它将更新标签,但是当我选择项目时它等于标签的null

    //update label type
    NSInteger row  = [singlePicker selectedRowInComponent:0];
   NSString *selected = [pickerData objectAtIndex:row];
   NSString *strTypeSelected  = [[NSString alloc] initWithFormat:@"%@",selected];


    typelabel.text =strTypeSelected;

首先,请确保将插座和数据源提供给UIPickerView singlePicker对象,然后尝试使用此代码。

typelabel.text = [pickerData  objectAtIndex:[singlePicker selectedRowInComponent:0]];

Try This, 尝试这个,

txtField1.text = [NSString stringWithFormat:@"%@",[arrData objectAtIndex:[picker selectedRowInComponent:0]]];

Check picker.delegate = self; 检查picker.delegate = self; in .m file -> viewDidLoad method. 在.m文件中-> viewDidLoad方法。

Check in .h File 签入.h文件

...Controller<UIPickerViewDataSource, UIPickerViewDelegate> {...

It may be help you. 可能会对您有所帮助。
Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM