我在我的viewController中有一個UIPickerView。我可以從委託方法如何獲取UIPickerView的選定值的行號
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
獲得所選擇的值的行數的值在選擇器,但在我的情況,我需要儘快獲得所選組件的行號出現的視圖。有沒有辦法在視圖出現後立即獲取行號/觸發委託方法。
我在我的viewController中有一個UIPickerView。我可以從委託方法如何獲取UIPickerView的選定值的行號
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
獲得所選擇的值的行數的值在選擇器,但在我的情況,我需要儘快獲得所選組件的行號出現的視圖。有沒有辦法在視圖出現後立即獲取行號/觸發委託方法。
您只需要使用selectedRowInComponent
selectedRowInComponent:
返回給定組件中選定行的索引。 - (NSInteger的)selectedRowInComponent:(NSInteger的)組件參數
部件
A zero-indexed number identifying a component of the picker view.
返回值
一個零索引號識別所選擇的行,或-1,如果沒有行被選中 。可用性
Available in iOS 2.0 and later.
請參見
– selectRow:inComponent:animated:
相關示例代碼
iPhoneCoreDataRecipes
宣佈UIPickerView.h
你pickerview
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *str= [yardsArray objectAtIndex:row];
}
使用這個代碼用這個選擇時,視圖將加載
-(void)ViewDidLoad
{
NSString *str= [yardsArray count];
}
當出現視圖時,我需要獲取當前選定值的行號 –
好的,您應該使用PickerView中的選擇指示器並檢查選擇指示器停止或可用的陣列的索引路徑。 – vishiphone
在viewDidLoad中
遍歷你的對象的數組,並匹配你想要找出該行的對象 ,並告訴我這是否是解決方案
然後,你應該在pickerview中計算你的選擇器數組。 – vishiphone