pickerview in tableview cell doesn't workUsing Auto Layout in UITableView for dynamic cell layouts & variable row heightsiOS 8 UITableView separator inset 0 not workingHow to detect tableView cell touched or clicked in swiftfatal error: Index out of range in swift while taking options from uipickerAdding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”Accessibility for pickerview Voice OverPickerView inside tableView cellSwift vertical UICollectionView inside UITableView3 Component Dynamic Multi UIPickerView SwiftGet index of component selected in UIPickerView Xcode Swift

Is there a POSIX way to shutdown a UNIX machine?

"Marked down as someone wanting to sell shares." What does that mean?

How do I lift the insulation blower into the attic?

Air travel with refrigerated insulin

How would a solely written language work mechanically

Connection Between Knot Theory and Number Theory

Why didn’t Eve recognize the little cockroach as a living organism?

Why would five hundred and five same as one?

A seasonal riddle

Are hand made posters acceptable in Academia?

Derivative of an interpolated function

How to test the sharpness of a knife?

Writing in a Christian voice

Mortal danger in mid-grade literature

Why is participating in the European Parliamentary elections used as a threat?

Does capillary rise violate hydrostatic paradox?

Put the phone down / Put down the phone

What can I do if I am asked to learn different programming languages very frequently?

C++ lambda syntax

What should be the ideal length of sentences in a blog post for ease of reading?

What is the purpose of using a decision tree?

Why is indicated airspeed rather than ground speed used during the takeoff roll?

Why can't I get pgrep output right to variable on bash script?

Hashing password to increase entropy



pickerview in tableview cell doesn't work


Using Auto Layout in UITableView for dynamic cell layouts & variable row heightsiOS 8 UITableView separator inset 0 not workingHow to detect tableView cell touched or clicked in swiftfatal error: Index out of range in swift while taking options from uipickerAdding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”Accessibility for pickerview Voice OverPickerView inside tableView cellSwift vertical UICollectionView inside UITableView3 Component Dynamic Multi UIPickerView SwiftGet index of component selected in UIPickerView Xcode Swift













0















When I try to use a pickerview to select tip amount, I have to relay that information to the view controller to be used by another tableview cell. When I reload the tableview, it reconfigures the pickerview in the cell, setting the tip to 0 when another amount was chosen. if I make it so the pickerview is only configured once by a bool statement that is true only the first time it configures, the pickerview freezes after the first selection, making a second adjustment impossible. When I tried to set the "selectRow" function to be the selected row and to reconfigure on the selected row, it doesn't work with the top and bottom fields writing over each other and the ability to update the tip stops working. I have no idea what other options there are for getting it work. Seems like this shouldn't be so difficult. Here's some code:



private func configurePickerView() 
let pickerView = UIPickerView()
pickerView.delegate = self
pickerView.dataSource = self
pickerView.selectRow(selectedRow, inComponent: 0, animated: false)
contentView.addSubview(pickerView)
pickerView.translatesAutoresizingMaskIntoConstraints = false
pickerView.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: 0.25).isActive = true
guard let orderView = orderView else return
pickerView.rightAnchor.constraint(equalTo: orderView.rightAnchor, constant: -20).isActive = true
pickerView.centerYAnchor.constraint(equalTo: orderView.centerYAnchor).isActive = true
//let height = getSize(large: 45, medium: 45, small: 45)
pickerView.heightAnchor.constraint(equalToConstant: 70).isActive = true



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


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

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
selectedRow = row
let tipAsInt = switchStatement(row)
delegate?.reloadData(tipAsInt)


private func switchStatement(_ row: Int) -> Int
switch row
case 0: return Int(round(0 * Double(subTotal)))
case 1: return Int(round(0.05 * Double(subTotal)))
case 2: return Int(round(0.1 * Double(subTotal)))
case 3: return Int(round(0.15 * Double(subTotal)))
case 4: return Int(round(0.2 * Double(subTotal)))
default: return Int(round(0.25 * Double(subTotal)))











share|improve this question


























    0















    When I try to use a pickerview to select tip amount, I have to relay that information to the view controller to be used by another tableview cell. When I reload the tableview, it reconfigures the pickerview in the cell, setting the tip to 0 when another amount was chosen. if I make it so the pickerview is only configured once by a bool statement that is true only the first time it configures, the pickerview freezes after the first selection, making a second adjustment impossible. When I tried to set the "selectRow" function to be the selected row and to reconfigure on the selected row, it doesn't work with the top and bottom fields writing over each other and the ability to update the tip stops working. I have no idea what other options there are for getting it work. Seems like this shouldn't be so difficult. Here's some code:



    private func configurePickerView() 
    let pickerView = UIPickerView()
    pickerView.delegate = self
    pickerView.dataSource = self
    pickerView.selectRow(selectedRow, inComponent: 0, animated: false)
    contentView.addSubview(pickerView)
    pickerView.translatesAutoresizingMaskIntoConstraints = false
    pickerView.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: 0.25).isActive = true
    guard let orderView = orderView else return
    pickerView.rightAnchor.constraint(equalTo: orderView.rightAnchor, constant: -20).isActive = true
    pickerView.centerYAnchor.constraint(equalTo: orderView.centerYAnchor).isActive = true
    //let height = getSize(large: 45, medium: 45, small: 45)
    pickerView.heightAnchor.constraint(equalToConstant: 70).isActive = true



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


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

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
    selectedRow = row
    let tipAsInt = switchStatement(row)
    delegate?.reloadData(tipAsInt)


    private func switchStatement(_ row: Int) -> Int
    switch row
    case 0: return Int(round(0 * Double(subTotal)))
    case 1: return Int(round(0.05 * Double(subTotal)))
    case 2: return Int(round(0.1 * Double(subTotal)))
    case 3: return Int(round(0.15 * Double(subTotal)))
    case 4: return Int(round(0.2 * Double(subTotal)))
    default: return Int(round(0.25 * Double(subTotal)))











    share|improve this question
























      0












      0








      0








      When I try to use a pickerview to select tip amount, I have to relay that information to the view controller to be used by another tableview cell. When I reload the tableview, it reconfigures the pickerview in the cell, setting the tip to 0 when another amount was chosen. if I make it so the pickerview is only configured once by a bool statement that is true only the first time it configures, the pickerview freezes after the first selection, making a second adjustment impossible. When I tried to set the "selectRow" function to be the selected row and to reconfigure on the selected row, it doesn't work with the top and bottom fields writing over each other and the ability to update the tip stops working. I have no idea what other options there are for getting it work. Seems like this shouldn't be so difficult. Here's some code:



      private func configurePickerView() 
      let pickerView = UIPickerView()
      pickerView.delegate = self
      pickerView.dataSource = self
      pickerView.selectRow(selectedRow, inComponent: 0, animated: false)
      contentView.addSubview(pickerView)
      pickerView.translatesAutoresizingMaskIntoConstraints = false
      pickerView.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: 0.25).isActive = true
      guard let orderView = orderView else return
      pickerView.rightAnchor.constraint(equalTo: orderView.rightAnchor, constant: -20).isActive = true
      pickerView.centerYAnchor.constraint(equalTo: orderView.centerYAnchor).isActive = true
      //let height = getSize(large: 45, medium: 45, small: 45)
      pickerView.heightAnchor.constraint(equalToConstant: 70).isActive = true



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


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

      func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
      selectedRow = row
      let tipAsInt = switchStatement(row)
      delegate?.reloadData(tipAsInt)


      private func switchStatement(_ row: Int) -> Int
      switch row
      case 0: return Int(round(0 * Double(subTotal)))
      case 1: return Int(round(0.05 * Double(subTotal)))
      case 2: return Int(round(0.1 * Double(subTotal)))
      case 3: return Int(round(0.15 * Double(subTotal)))
      case 4: return Int(round(0.2 * Double(subTotal)))
      default: return Int(round(0.25 * Double(subTotal)))











      share|improve this question














      When I try to use a pickerview to select tip amount, I have to relay that information to the view controller to be used by another tableview cell. When I reload the tableview, it reconfigures the pickerview in the cell, setting the tip to 0 when another amount was chosen. if I make it so the pickerview is only configured once by a bool statement that is true only the first time it configures, the pickerview freezes after the first selection, making a second adjustment impossible. When I tried to set the "selectRow" function to be the selected row and to reconfigure on the selected row, it doesn't work with the top and bottom fields writing over each other and the ability to update the tip stops working. I have no idea what other options there are for getting it work. Seems like this shouldn't be so difficult. Here's some code:



      private func configurePickerView() 
      let pickerView = UIPickerView()
      pickerView.delegate = self
      pickerView.dataSource = self
      pickerView.selectRow(selectedRow, inComponent: 0, animated: false)
      contentView.addSubview(pickerView)
      pickerView.translatesAutoresizingMaskIntoConstraints = false
      pickerView.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: 0.25).isActive = true
      guard let orderView = orderView else return
      pickerView.rightAnchor.constraint(equalTo: orderView.rightAnchor, constant: -20).isActive = true
      pickerView.centerYAnchor.constraint(equalTo: orderView.centerYAnchor).isActive = true
      //let height = getSize(large: 45, medium: 45, small: 45)
      pickerView.heightAnchor.constraint(equalToConstant: 70).isActive = true



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


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

      func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
      selectedRow = row
      let tipAsInt = switchStatement(row)
      delegate?.reloadData(tipAsInt)


      private func switchStatement(_ row: Int) -> Int
      switch row
      case 0: return Int(round(0 * Double(subTotal)))
      case 1: return Int(round(0.05 * Double(subTotal)))
      case 2: return Int(round(0.1 * Double(subTotal)))
      case 3: return Int(round(0.15 * Double(subTotal)))
      case 4: return Int(round(0.2 * Double(subTotal)))
      default: return Int(round(0.25 * Double(subTotal)))








      swift uitableview uipickerview






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 20:26









      michaeldebomichaeldebo

      799




      799






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You need to make



          let pickerView = UIPickerView()


          and instance var , so it's delegate and dataSource are retained



          Also you should call



          func configurePickerView() { // call it inside awakeFromNib or init


          once as not to add multiple pickers to the tableCell and when you need a refresh call



          pickerView.reloadAllComponents()





          share|improve this answer

























          • the picker delegate and datasource refers to the cell which is retained , but i'm speaking about the item itself here it's pickerView as it's a local variable , plus the op needs a reference to it for upcoming refresh

            – Sh_Khan
            Mar 7 at 21:02












          • Sh_Khan is right. I needed to make it an instance variable, declaring it outside the configurePickerView function. It works perfectly reconfiguring it each time now, without needing to call pickerView.reloadAllComponents(), though that may be best practice.

            – michaeldebo
            Mar 7 at 21:26










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052265%2fpickerview-in-tableview-cell-doesnt-work%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You need to make



          let pickerView = UIPickerView()


          and instance var , so it's delegate and dataSource are retained



          Also you should call



          func configurePickerView() { // call it inside awakeFromNib or init


          once as not to add multiple pickers to the tableCell and when you need a refresh call



          pickerView.reloadAllComponents()





          share|improve this answer

























          • the picker delegate and datasource refers to the cell which is retained , but i'm speaking about the item itself here it's pickerView as it's a local variable , plus the op needs a reference to it for upcoming refresh

            – Sh_Khan
            Mar 7 at 21:02












          • Sh_Khan is right. I needed to make it an instance variable, declaring it outside the configurePickerView function. It works perfectly reconfiguring it each time now, without needing to call pickerView.reloadAllComponents(), though that may be best practice.

            – michaeldebo
            Mar 7 at 21:26















          1














          You need to make



          let pickerView = UIPickerView()


          and instance var , so it's delegate and dataSource are retained



          Also you should call



          func configurePickerView() { // call it inside awakeFromNib or init


          once as not to add multiple pickers to the tableCell and when you need a refresh call



          pickerView.reloadAllComponents()





          share|improve this answer

























          • the picker delegate and datasource refers to the cell which is retained , but i'm speaking about the item itself here it's pickerView as it's a local variable , plus the op needs a reference to it for upcoming refresh

            – Sh_Khan
            Mar 7 at 21:02












          • Sh_Khan is right. I needed to make it an instance variable, declaring it outside the configurePickerView function. It works perfectly reconfiguring it each time now, without needing to call pickerView.reloadAllComponents(), though that may be best practice.

            – michaeldebo
            Mar 7 at 21:26













          1












          1








          1







          You need to make



          let pickerView = UIPickerView()


          and instance var , so it's delegate and dataSource are retained



          Also you should call



          func configurePickerView() { // call it inside awakeFromNib or init


          once as not to add multiple pickers to the tableCell and when you need a refresh call



          pickerView.reloadAllComponents()





          share|improve this answer















          You need to make



          let pickerView = UIPickerView()


          and instance var , so it's delegate and dataSource are retained



          Also you should call



          func configurePickerView() { // call it inside awakeFromNib or init


          once as not to add multiple pickers to the tableCell and when you need a refresh call



          pickerView.reloadAllComponents()






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 at 21:03

























          answered Mar 7 at 20:45









          Sh_KhanSh_Khan

          45.7k51432




          45.7k51432












          • the picker delegate and datasource refers to the cell which is retained , but i'm speaking about the item itself here it's pickerView as it's a local variable , plus the op needs a reference to it for upcoming refresh

            – Sh_Khan
            Mar 7 at 21:02












          • Sh_Khan is right. I needed to make it an instance variable, declaring it outside the configurePickerView function. It works perfectly reconfiguring it each time now, without needing to call pickerView.reloadAllComponents(), though that may be best practice.

            – michaeldebo
            Mar 7 at 21:26

















          • the picker delegate and datasource refers to the cell which is retained , but i'm speaking about the item itself here it's pickerView as it's a local variable , plus the op needs a reference to it for upcoming refresh

            – Sh_Khan
            Mar 7 at 21:02












          • Sh_Khan is right. I needed to make it an instance variable, declaring it outside the configurePickerView function. It works perfectly reconfiguring it each time now, without needing to call pickerView.reloadAllComponents(), though that may be best practice.

            – michaeldebo
            Mar 7 at 21:26
















          the picker delegate and datasource refers to the cell which is retained , but i'm speaking about the item itself here it's pickerView as it's a local variable , plus the op needs a reference to it for upcoming refresh

          – Sh_Khan
          Mar 7 at 21:02






          the picker delegate and datasource refers to the cell which is retained , but i'm speaking about the item itself here it's pickerView as it's a local variable , plus the op needs a reference to it for upcoming refresh

          – Sh_Khan
          Mar 7 at 21:02














          Sh_Khan is right. I needed to make it an instance variable, declaring it outside the configurePickerView function. It works perfectly reconfiguring it each time now, without needing to call pickerView.reloadAllComponents(), though that may be best practice.

          – michaeldebo
          Mar 7 at 21:26





          Sh_Khan is right. I needed to make it an instance variable, declaring it outside the configurePickerView function. It works perfectly reconfiguring it each time now, without needing to call pickerView.reloadAllComponents(), though that may be best practice.

          – michaeldebo
          Mar 7 at 21:26



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052265%2fpickerview-in-tableview-cell-doesnt-work%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme