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
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
add a comment |
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
add a comment |
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
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
swift uitableview uipickerview
asked Mar 7 at 20:26
michaeldebomichaeldebo
799
799
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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()
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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()
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
add a comment |
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()
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
add a comment |
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()
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()
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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