簡體   English   中英

在單個選擇器中選擇的項目為null

[英]selected Item in single picker is null

我有一個選擇器,當用戶選擇類型時它將更新標簽,但是當我選擇項目時它等於標簽的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]];

嘗試這個,

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

檢查picker.delegate = self; 在.m文件中-> viewDidLoad方法。

簽入.h文件

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

可能會對您有所幫助。
謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM