logo
down
shadow

How can I add search option on UIPickerview in ios?


How can I add search option on UIPickerview in ios?

By : pranjl
Date : November 24 2020, 03:01 PM
it should still fix some issue If Anyone wants it in swift... Create a textField with name txtSearch and then in ViewDidload add below two lines
code :
self.txtSearch.delegate=self
self.txtSearch.addTarget(self, action: #selector(self.textFieldValueChanged(TextField:)), for: UIControlEvents.editingChanged)

func textFieldValueChanged(TextField:UITextField)

{

    if((TextField.text?.characters.count)!>0)
    {
        self.filteredArray = (self.searchInArray(srchArray: self.ArraywithFullData, withKey: "key value", Characters: TextField.text!))!
    }
    else
    {

        self.filteredArray = self.ArraywithFullData.mutableCopy() as! NSMutableArray
    }

    self.pickerView.reloadData()


}
func searchInArray(srchArray:NSMutableArray, withKey:String,Characters:String)->NSMutableArray
{

    let resultArray=NSMutableArray()
    for index in 0..<srchArray.count
    {
        let Dict  = srchArray[index] as! [String:Any]
        if let stringmatcher = Dict[withKey] as? String
        {
            if(stringmatcher.contains(find: Characters))
            {
                resultArray.add(Dict)

            }
            else
            {

            }
        }

    }

 return resultArray

}
extension String {

func contains(find: String) -> Bool{
    return self.range(of: find) != nil
}
NSMutableArray *filteredArray;
NSMutableArray *ArraywithFullData;
self.txtSearch.delegate=self
[self.txtSearch addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
//

-(void)textFieldValueChanged:(UITextField *)TextField

{

    if((TextField.text.length)>0)
    {
        filteredArray = [self  searchInArray:ArraywithFullData withKey:@"key value" andCharacters:TextField.text];

    }
    else
    {

        filteredArray = [ArraywithFullData mutableCopy];
    }

    [self.pickerView reloadData];


}
-(NSMutableArray *)searchInArray:(NSMutableArray*)srchArray withKey:(NSString *)key andCharacters:(NSString *)charecters
{

    NSMutableArray *resultArray= [[NSMutableArray alloc]init];
    for (int index=0 ; index<srchArray.count; index++)
    {
        NSMutableDictionary *Dict  = srchArray[index];
        if ([Dict valueForKey:key] != nil)
        {
            NSString * stringmatcher = [Dict valueForKey:key];
            if ([stringmatcher containsString:charecters])
            {
                [resultArray addObject:Dict];

            }
            else
            {

            }
        }

    }

    return resultArray;

}


Share : facebook icon twitter icon
Remove 'search' option but leave 'search columns' option

Remove 'search' option but leave 'search columns' option


By : Nagender Raj Ayyappa
Date : March 29 2020, 07:55 AM
Any of those help DT options needs to be passed as a list. Further, by using the sDom initialisation variable it is possible to specify where in the DOM controls are placed. The standard setup looks like this:
code :
    datatable(iris, filter="top", selection="multiple", escape=FALSE, 
      options = list(sDom  = '<"top">flrt<"bottom">ip'))
    datatable(iris, filter="top", selection="multiple", escape=FALSE, 
      options = list(sDom  = '<"top">lrt<"bottom">ip'))
I want to save a Selected Option in a Swift UIPickerView

I want to save a Selected Option in a Swift UIPickerView


By : user1547470
Date : March 29 2020, 07:55 AM
wish help you to fix your issue You can simply save the selected row number in UserDefaults so that it can be accessed next time.
code :
// Capture the picker view selection
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    selected = measurementTypes[row]
    // Save selected row integer in User Defaults
    UserDefaults.standard.set(row, forKey: "pickerViewRow")
}
let row = UserDefaults.standard.integer(forKey: "pickerViewRow")
pickerView.selectRow(row, inComponent: 0, animated: False)
UIPickerView with a custom UITextField option

UIPickerView with a custom UITextField option


By : user1703226
Date : March 29 2020, 07:55 AM
this will help According to my opinion, the solution is: In your code, you are showing picker in place of a keyboard, it's correct. Now when a user selects "Other", simply show selected value "Other" in cameraBodyTextField. And show one extra text field just below cameraBodyTextField. Show/Hide can be managed by autolayout hight constraints with smoother animation.
Filling a UITextField with a UIPickerView option immediately

Filling a UITextField with a UIPickerView option immediately


By : Mattheus
Date : March 29 2020, 07:55 AM
Does that help You need to implement textFieldShouldBeginEditing: method.
Set delegate
code :
yourTextfield.delegate = self
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {


     if (textField == yourTextfield) {  

        // your logic goes here...
        yourTextfield.text = prevCardiacIntervPickerOption.first

     }

   return true
}
Swift UIPickerView defaults to last option regardless of selected option

Swift UIPickerView defaults to last option regardless of selected option


By : ativaishna
Date : October 02 2020, 09:00 PM
To fix this issue It seems to be a bug in the simulator. I tested the my code above and the code provided by Abdul Karim Khan on my device and the work as they should. The label updates according to the option selected in the picker view.
shadow
Privacy Policy - Terms - Contact Us © voile276.org