logo
down
shadow

PickerView not showing any values


PickerView not showing any values

By : user2957642
Date : November 24 2020, 01:01 AM
I wish did fix the issue. guys for the comments, I found the issue... I forgot to set the delegate to self in the viewDidLoad, I only implemented the delegate class, sure that can't work ;-)
code :


Share : facebook icon twitter icon
Data from array is not showing up in the pickerView

Data from array is not showing up in the pickerView


By : Crystalmiles Kilat M
Date : March 29 2020, 07:55 AM
it fixes the issue I am trying to do Single-Component Picker example Beginning iOS 6 Development Book, almost every thing works fine but Data from array is not showing up in the pickerView Please Help , You need to alloc your NSArray object as follows:
code :
self.chaNames = [NSArray alloc] initWithObjects:@"Luke",@"Leia",@"Han",@"Chewbacca",@"Artoo", @"Threepio",@"lando"];
-(void)viewDidLoad {

    self.chaNames = [NSArray alloc] initWithObjects:@"Luke",@"Leia",@"Han",@"Chewbacca",@"Artoo", @"Threepio",@"lando"];
}
How to show PickerView Values Based on Previous PickerView Using TextField Click in iOS?

How to show PickerView Values Based on Previous PickerView Using TextField Click in iOS?


By : Tilap
Date : March 29 2020, 07:55 AM
hope this fix your issue Here is the updated code with tested:
First in .h file declare this:
code :
UIView *_viewForPicker;
UIPickerView *_regionPicker;
NSArray *regionArray;
NSArray *chennaiSouthArray;
NSArray *chennaiNorthArray;
NSArray *villupuramArray;
int selectionVal;
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = self.editButtonItem;
    //static Array for RegionPicker
    regionArray = [[NSArray alloc] initWithObjects:@"Chennai-south",@"Chennai-north",@"Villupuram", nil];

    //static Array for SectionPicker
    chennaiSouthArray = [[NSArray alloc]initWithObjects:@"A",@"B",@"C", nil];
    chennaiNorthArray = [[NSArray alloc]initWithObjects:@"D",@"E",@"F", nil];
    villupuramArray = [[NSArray alloc]initWithObjects:@"D",@"E",@"F", nil];

    //static Array for DistributionPicker
    NSArray *aArray = [[NSArray alloc]initWithObjects:@"a",@"b", nil];
    NSArray *bArray = [[NSArray alloc]initWithObjects:@"c",@"d", nil];
    NSArray *cArray = [[NSArray alloc]initWithObjects:@"e",@"f", nil];
    NSArray *dArray = [[NSArray alloc]initWithObjects:@"g",@"h", nil];
    NSArray *eArray = [[NSArray alloc]initWithObjects:@"i",@"j", nil];


    //viewForPicker
    _viewForPicker = [[UIView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.height, self.view.frame.size.width,260)];
    _viewForPicker.backgroundColor = [UIColor blackColor];
    [self.view addSubview:_viewForPicker];

    //regionPickerView
    _regionPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 216)];
    _regionPicker.delegate = self;
    _regionPicker.dataSource = self;
    _regionPicker.showsSelectionIndicator = YES;
    [_regionPicker setBackgroundColor:[UIColor lightGrayColor]];
    [_viewForPicker addSubview:_regionPicker];

    //ToolBar
    UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,44)];
    [toolBar setBarStyle:UIBarStyleBlackOpaque];
    UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(hidePickerView:)];
    toolBar.items = @[barButtonDone];
    barButtonDone.tintColor=[UIColor lightTextColor];
    [barButtonDone setEnabled:YES];
    [_viewForPicker addSubview:toolBar];

    //SettingLabels
    [self setView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

-(void)hidePickerView:(id)sender {
    [UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
        _viewForPicker.frame = CGRectMake(0, self.view.frame.size.height, 320, 260);
    } completion:^(BOOL finished){
    }];
}

-(void)setView {
    //regionLabel
    UILabel *regionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+30, self.view.frame.origin.y+30, 60, 25)];
    [regionLabel setText:@"Region"];
    [self.view addSubview:regionLabel];

    //regionText
    UITextField *regionText = [[UITextField alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+120, self.view.frame.origin.y+30, 150, 25)];
    [regionText setBorderStyle:UITextBorderStyleRoundedRect];
    [regionText setPlaceholder:@"selectRegion"];
    [regionText setTag:51];
    [regionText setDelegate:self];
    [self.view addSubview:regionText];

    //sectionLabel
    UILabel *sectionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+30, self.view.frame.origin.y+120, 60, 25)];
    [sectionLabel setText:@"Section"];
    [self.view addSubview:sectionLabel];

    //sectionText
    UITextField *sectionText = [[UITextField alloc] initWithFrame:CGRectMake(self.view.frame.origin.x+120, self.view.frame.origin.y+120, 150, 25)];
    [sectionText setBorderStyle:UITextBorderStyleRoundedRect];
    [sectionText setPlaceholder:@"selectSection"];
    [sectionText setTag:52];
    [sectionText setDelegate:self];
    [self.view addSubview:sectionText];

    //distributionLabel
    UILabel *distributionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+30, self.view.frame.origin.y+210, 90, 25)];
    [distributionLabel setText:@"Distribution"];
    [self.view addSubview:distributionLabel];

    //distributionText
    UITextField *distributionText = [[UITextField alloc]initWithFrame:CGRectMake(self.view.frame.origin.x+120, self.view.frame.origin.y+210, 150, 25)];
    [distributionText setBorderStyle:UITextBorderStyleRoundedRect];
    [distributionText setPlaceholder:@"selectDistribution"];
    [distributionText setTag:53];
    [distributionText setDelegate:self];
    [self.view addSubview:distributionText];

}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    // Show UIPickerView
    if (textField.tag == 51){
        NSLog(@"Entering Textfield Begin");
        selectionVal = 1;
        [UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
            _viewForPicker.frame = CGRectMake(0, self.view.frame.size.height-260,self.view.frame.size.width, 260);
        }completion:^(BOOL finished){}];
    }else if(textField.tag == 52){
        if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@""]) {
            [[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Set Region First" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil] show];
        }else {
            selectionVal = 2;
            [UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
                _viewForPicker.frame = CGRectMake(0, self.view.frame.size.height-260,self.view.frame.size.width, 260);
            }completion:^(BOOL finished){}];
        }
    }else if (textField.tag == 53){
        if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@""]) {
            [[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Set Region First" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil] show];
        }else{
            selectionVal = 3;
            [UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
                _viewForPicker.frame = CGRectMake(0, self.view.frame.size.height-260,self.view.frame.size.width, 260);
            }completion:^(BOOL finished){}];
        }
    }
    [_regionPicker reloadAllComponents];
    return NO;
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component{
    if(selectionVal == 1){
        return [regionArray count];
    }else if(selectionVal == 2){
        if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-south"]) {
            return chennaiSouthArray.count;
        }else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-north"]){
            return chennaiNorthArray.count;
        }else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Villupuram"]){
            return villupuramArray.count;
        }
    }else if(selectionVal == 3){
    }
    return 0;
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component  {
    if(selectionVal == 1){
        return [regionArray objectAtIndex:row];
    }else if(selectionVal == 2){
        if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-south"]) {
            return [chennaiSouthArray objectAtIndex:row];
        }else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-north"]){
            return [chennaiNorthArray objectAtIndex:row];
        }else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Villupuram"]){
            return [villupuramArray objectAtIndex:row];
        }
    }
    return @"test";
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if(selectionVal == 1){
        [(UITextField*)[self.view viewWithTag:51] setText:[regionArray objectAtIndex:row]];
    }else if(selectionVal == 2){
        if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-south"]) {
            [(UITextField*)[self.view viewWithTag:52] setText:[chennaiSouthArray objectAtIndex:row]];
        }else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Chennai-north"]){
            [(UITextField*)[self.view viewWithTag:52] setText:[chennaiNorthArray objectAtIndex:row]];
        }else if ([[(UITextField*)[self.view viewWithTag:51] text] isEqualToString:@"Villupuram"]){
            [(UITextField*)[self.view viewWithTag:53] setText:[villupuramArray objectAtIndex:row]];
        }

    }
}
Showing data from pickerview

Showing data from pickerview


By : Jezzo
Date : March 29 2020, 07:55 AM
wish of those help I have designed a tableview cell with a textfield for pickerview. AndI have loaded 2 of those cells in my tableview. In order to show data from the pickerview this is what I did in cellForRowAt... , Problem :
As somebody mentioned in answer above
code :
class MyPickerView : UIPickerView {
    weak var cell : MyTableViewCell? = nil
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   let cell: sellTableViewCell = tableView.dequeueReusableCell(withIdentifier: "sellProductIdentifier") as! sellTableViewCell
        cell.delegate = self

        let pickerView = MyPickerView()
        pickerView.cell = cell //pass cells reference 
        pickerView.delegate = self
        cell.pickerField.inputView = pickerView
        //other code
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        if pickerView is MyPickerView {
            if let cell = (pickerView as! MyPickerView).cell {
                cell.textField?.text = myData[row]
                let indexPath = self.tableView.indexPath(for: cell)
                if let index  = indexPath {
                    //now go ahead and update your data
                }

            }

        }
    }
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

        if pickerView is MyPickerView {

            if let cell = (pickerView as! MyPickerView).cell {

                cell.qtyPickerField.text = myData[row]
                let indexPath = self.tableview.indexPath(for: cell)
                if let index = indexPath {
                    //this is only to show you how you can access indexPath
                    //and in future if you need to update your data source you can use it
                    //for now ignore this :)
                }
            }

        }
    }
Content in PickerView not showing up

Content in PickerView not showing up


By : user2147861
Date : March 29 2020, 07:55 AM
Hope this helps I think you haven’t set your pickers’ delegates and data sources.
First add these protocols to your ViewController subclass
code :
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource
override func viewDidLoad() {
    super.viewDidLoad()
    pickerView1.delegate = self
    pickerView1.dataSource = self
    pickerView2.delegate = self
    pickerView2.dataSource = self
}
Swift 4.2 - PickerView not showing Content

Swift 4.2 - PickerView not showing Content


By : DsTr
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , First, you do not need to do the separate array of gender in pickerview class and you don't need to create the instance of pickerview.
From this, you can see your datasource in your custompickerview
code :
/**
Controller code where you can create instantiate picker assign data 

*/
    class ViewController: UIViewController {

        @IBOutlet weak var textField: UITextField!            
        let genderPickerData : [String] = ["male", "female"]

        override func viewDidLoad() {
            super.viewDidLoad()

            prepareView()
        }

        func prepareView() {

            genderPickerView = UIPickerView()

            let gpModel = GenderPickerModel()

            gpModel.data = genderPickerData

            gpModel.dataSource = gpModel
            gpModel.delegate = gpModel
            textField.inputView = gpModel

        }
    }

/**

Custom pickerview class where you can handle data 

*/
import UIKit

class GenderPickerModel: UIPickerView, UIPickerViewDataSource, UIPickerViewDelegate {

    var data = [String]()

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return data.count
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return data[row]
    }

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    }

}
Related Posts Related Posts :
  • Unclear about releasing CFDictionaryRef
  • CordovaError: Promise rejected with non-error: Error code 65
  • How to append NSMutable strings into a UILabel
  • CustomCell label value does not change
  • Display ad in iAd Bannerview iAd Network
  • Warning: "Could not get traitsetID for iPhone11,6" (Assets.xcassets)
  • Changing root view controller after iOS app has loaded.
  • SocketRocket and iOS certificate pinning
  • Draggable UIButton Snap To a Circle Path
  • Running FireBase in the background
  • resizing UIPopoverController to fit UITableController
  • UICollectionView Exception Crash
  • targeting iOS5 - will it work on iOS6 also?
  • FBLoginView get email
  • Scale UIImages height to UIImageView height
  • Creating a custom progress indicator in ios
  • NSRunLoop API difference
  • Is it possible to inject custom settings into my iOS application "Notifications" settings dialog?
  • UIAlertview not accepting string as message
  • Axis change of stackView giving layout error
  • How to use AVAssetResourceLoader?
  • How to write block definition using properties?
  • iOS connect/reconnect to Bluetooth device when using external-accessory and MFi
  • Saving XMPP Multi User chat messages through XMPP MessageArchiving in iOS
  • Deciding iOS version: pros and cons
  • iOS: Resigned app cannot access keychain through security API
  • How can I set To and Subject fields in an E-Mail being sent by UIDocumentInteractionController?
  • Updating uilabel in view controller underneath another
  • Maximum time Intervel for NSTimer
  • Delete Core Data Entry from Table View Controller
  • How to unload UIViewcontroller from memory?
  • Compressing UIImage as Far as Possible?
  • Optimizing workflow to update internally owned cocoapods dependencies?
  • Formatting an NSDate with Abbreviated Month/Day Names
  • I'm creating a quiz game with 4 answers and I want to add score
  • Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org