I am using picker view in my application, I am selecting the object but object is not showing on the label,
Please help me
pragma mark- PICKER_VIEW_Delegate_Methods ----------------->>>>
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
// The number of rows of data
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if(pickerView == countryPicker)
{
return [arrayCountry count];
}
if(pickerView == statePicker)
{
return [stateArray count];
}
else return 5;
}
// The data to return for the row and component (column) that's being passed in
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if(pickerView == countryPicker)
{
return [arrayCountry objectAtIndex:row];
}
if(pickerView == statePicker)
{
return [stateArray objectAtIndex:row];
}
return @"";
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(pickerView == countryPicker)
{
countryLabel.text = countryArray[row];
countryPicker.hidden = YES;
NSLog(@"statelabel %@",countryLabel.text);
}
if(pickerView == statePicker)
{
[stateLabel setText:[stateArray objectAtIndex:row]];
statePicker.hidden = YES;
}
}
- (IBAction)countryList:(id)sender
{
countryPicker.hidden = false;
[countryPicker reloadAllComponents];
}
- (IBAction)stateList:(id)sender
{
stateArray = [DictStates valueForKeyPath:countryStr];
statePicker.hidden = false;
stateTable.hidden = FALSE;
[statePicker reloadAllComponents];
}
- (void)getCountryStatesList
{
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@"http://dev-demo.info.bh-in-15.webhostbox.net/dv/nationalblack/api/countrystate"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"List : %@", json);
dispatch_async(dispatch_get_main_queue(), ^{
[self parseCountryStates:json];
});
}];
[dataTask resume];
}
- (void)parseCountryStates:(NSDictionary *)json
{
NSArray *listing = [json objectForKey:@"listing"];
arrayCountry = [[NSSet setWithArray:[listing valueForKey:@"country"]] allObjects];
NSArray *states;
NSMutableDictionary *tempStates = [NSMutableDictionary new];
for (NSString *countryName in arrayCountry) {
NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@", @"country", countryName];
NSLog(@"predicate %@",predicateString);
states = [NSMutableArray arrayWithArray:[listing filteredArrayUsingPredicate:predicateString]];
[tempStates setObject:states forKey:countryName];
}
DictStates = tempStates;
}
now country is selected but now when i click on state button it creashed
i am sharing my crash log:
> -[__NSCFDictionary length]: unrecognized selector sent to instance 0x7f98c9683220
> 2016-06-13 11:30:54.912 [1745:52321] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
> '-[__NSCFDictionary length]: unrecognized selector sent to instance
> 0x7f98c9683220'
> *** First throw call stack:
0
A
回答
0
Replace Your method with
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(pickerView == countryPicker)
{
countryLabel.text = arrayCountry[row];
countryPicker.hidden = YES;
NSLog(@"statelabel %@",countryLabel.text);
}
if(pickerView == statePicker)
{
[stateLabel setText:[stateArray objectAtIndex:row]];
statePicker.hidden = YES;
}
}
Will solve your problem :)
+0
謝謝它的作品,但我有另一個問題,當我選擇狀態按鈕它沒有顯示狀態列表 – Abhi
+0
你有statePicker。隱藏= YES;在你的代碼,所以,在按鈕操作你應該隱藏到false,並重新加載選擇器視圖將幫助 –
+0
請修復numberOfRowsInComponent,你應該使用其他if,if,if和else, –
相關問題
- 1. 所有未選擇的選項標籤
- 2. 更改所選行標籤顏色選擇器視圖SWIFT 1.2
- 3. Angularjs:獲得所選對象的指數選擇標籤
- 4. 從選擇標籤
- 5. 突出顯示從鍵盤輸入選擇標籤選項
- 6. jquery選擇器 - 選擇id不等於的所有span標籤
- 7. JSON2HTML - 選擇標籤正在JSON對象
- 8. 對HTML5標籤的CSS選擇器 「CONTENTEDITABLE」
- 9. 使用CSS選擇器選擇標籤
- 10. amCharts設置圖例標籤選擇/未選擇編程
- 11. 獲取所選擇的選項標籤的價值選擇框
- 12. 選擇選擇顯示組標籤和選項選擇
- 13. 選擇標籤的選項右對齊
- 14. Rails堆棧溢出標籤選擇器
- 15. 顯示標籤和c選擇標籤
- 16. 顯示選擇標籤欄項目時的模式視圖
- 17. 從滾動視圖中選擇圖標
- 18. 標籤欄圖標選擇的圖像
- 19. 在對話框中取消選擇的視圖選擇顯示
- 20. 選擇標籤顯示小寫選項
- 21. 如何突出顯示從comboBox中選擇的特定標籤?
- 22. 類別/標籤選擇器
- 23. jQuery標籤選擇器
- 24. 標籤選擇器控件
- 25. jQuery UI的日期選擇器:下面對準標籤發出
- 26. 當選擇標籤時彈出到根視圖
- 27. css複選框標籤選擇器
- 28. UIWebView從座標DOM選擇對象
- 29. 即使設置了視圖對象,選擇框也未設置?
- 30. 選擇標籤/選項標籤麻煩
我認爲這種線'countryLabel.text = countryArray [行]上;'應'countryLabel.text = arrayCountry [行];' –
@ EICaptainv2 .0感謝它的作品,但我有另一個問題,當我選擇狀態按鈕它沒有顯示狀態列表 – Abhi