Can't change input Value in Swift 4.2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have an input UITextField
and want to change his value.
I defined this UITextField
like this:
@IBOutlet weak var valueInput: UITextField!
Than in viewDidLoad()
I make delegate
- self
:
valueInput?.delegate = self
and then in viewDidLoad
I try to assign value to input like this:
if let priceIn = self.valueIn Input {
valueIn.text! = strPr // (this is var and it has String format I've checked it, and I also try to make print(strPr) and I get a value)
}
Unfortunately this string is not working:
valueIn.text! = strPr
But if I write something like this
valueIn.text! = "11"
This one will work.
I've tried to to something like this also, but it's not working also:
valueIn.text! = "(strPr)"
Anyone have any ideas?
Thanks for any answer, hope somebody had the same problem and know how to resolve it.
ios swift swift4.2 xcode10.1
|
show 6 more comments
I have an input UITextField
and want to change his value.
I defined this UITextField
like this:
@IBOutlet weak var valueInput: UITextField!
Than in viewDidLoad()
I make delegate
- self
:
valueInput?.delegate = self
and then in viewDidLoad
I try to assign value to input like this:
if let priceIn = self.valueIn Input {
valueIn.text! = strPr // (this is var and it has String format I've checked it, and I also try to make print(strPr) and I get a value)
}
Unfortunately this string is not working:
valueIn.text! = strPr
But if I write something like this
valueIn.text! = "11"
This one will work.
I've tried to to something like this also, but it's not working also:
valueIn.text! = "(strPr)"
Anyone have any ideas?
Thanks for any answer, hope somebody had the same problem and know how to resolve it.
ios swift swift4.2 xcode10.1
What do you mean by "it's not working"? Do you get a compile time error? What is the type ofvalueIn
?
– Daniel T.
Nov 16 '18 at 14:04
self.valueIn Input
— what does it even mean? It is not valid Swift.
– user28434
Nov 16 '18 at 14:10
1
Show the code wherestrPr
is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you meanif let priceIn = self.valueInput
this optional binding is pointless because the outlet is connected reliably beforeviewDidLoad
is called.
– vadian
Nov 16 '18 at 14:14
Yesprint(strPr
) beforevalueIn.text! = strPr
– canister_exister
Nov 16 '18 at 14:47
Delete this lineif let priceIn = self.valueIn Input {
– canister_exister
Nov 16 '18 at 14:52
|
show 6 more comments
I have an input UITextField
and want to change his value.
I defined this UITextField
like this:
@IBOutlet weak var valueInput: UITextField!
Than in viewDidLoad()
I make delegate
- self
:
valueInput?.delegate = self
and then in viewDidLoad
I try to assign value to input like this:
if let priceIn = self.valueIn Input {
valueIn.text! = strPr // (this is var and it has String format I've checked it, and I also try to make print(strPr) and I get a value)
}
Unfortunately this string is not working:
valueIn.text! = strPr
But if I write something like this
valueIn.text! = "11"
This one will work.
I've tried to to something like this also, but it's not working also:
valueIn.text! = "(strPr)"
Anyone have any ideas?
Thanks for any answer, hope somebody had the same problem and know how to resolve it.
ios swift swift4.2 xcode10.1
I have an input UITextField
and want to change his value.
I defined this UITextField
like this:
@IBOutlet weak var valueInput: UITextField!
Than in viewDidLoad()
I make delegate
- self
:
valueInput?.delegate = self
and then in viewDidLoad
I try to assign value to input like this:
if let priceIn = self.valueIn Input {
valueIn.text! = strPr // (this is var and it has String format I've checked it, and I also try to make print(strPr) and I get a value)
}
Unfortunately this string is not working:
valueIn.text! = strPr
But if I write something like this
valueIn.text! = "11"
This one will work.
I've tried to to something like this also, but it's not working also:
valueIn.text! = "(strPr)"
Anyone have any ideas?
Thanks for any answer, hope somebody had the same problem and know how to resolve it.
ios swift swift4.2 xcode10.1
ios swift swift4.2 xcode10.1
edited Nov 16 '18 at 14:07
vadian
156k17166192
156k17166192
asked Nov 16 '18 at 13:54
Vitaliy MckayVitaliy Mckay
709
709
What do you mean by "it's not working"? Do you get a compile time error? What is the type ofvalueIn
?
– Daniel T.
Nov 16 '18 at 14:04
self.valueIn Input
— what does it even mean? It is not valid Swift.
– user28434
Nov 16 '18 at 14:10
1
Show the code wherestrPr
is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you meanif let priceIn = self.valueInput
this optional binding is pointless because the outlet is connected reliably beforeviewDidLoad
is called.
– vadian
Nov 16 '18 at 14:14
Yesprint(strPr
) beforevalueIn.text! = strPr
– canister_exister
Nov 16 '18 at 14:47
Delete this lineif let priceIn = self.valueIn Input {
– canister_exister
Nov 16 '18 at 14:52
|
show 6 more comments
What do you mean by "it's not working"? Do you get a compile time error? What is the type ofvalueIn
?
– Daniel T.
Nov 16 '18 at 14:04
self.valueIn Input
— what does it even mean? It is not valid Swift.
– user28434
Nov 16 '18 at 14:10
1
Show the code wherestrPr
is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you meanif let priceIn = self.valueInput
this optional binding is pointless because the outlet is connected reliably beforeviewDidLoad
is called.
– vadian
Nov 16 '18 at 14:14
Yesprint(strPr
) beforevalueIn.text! = strPr
– canister_exister
Nov 16 '18 at 14:47
Delete this lineif let priceIn = self.valueIn Input {
– canister_exister
Nov 16 '18 at 14:52
What do you mean by "it's not working"? Do you get a compile time error? What is the type of
valueIn
?– Daniel T.
Nov 16 '18 at 14:04
What do you mean by "it's not working"? Do you get a compile time error? What is the type of
valueIn
?– Daniel T.
Nov 16 '18 at 14:04
self.valueIn Input
— what does it even mean? It is not valid Swift.– user28434
Nov 16 '18 at 14:10
self.valueIn Input
— what does it even mean? It is not valid Swift.– user28434
Nov 16 '18 at 14:10
1
1
Show the code where
strPr
is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you mean if let priceIn = self.valueInput
this optional binding is pointless because the outlet is connected reliably before viewDidLoad
is called.– vadian
Nov 16 '18 at 14:14
Show the code where
strPr
is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you mean if let priceIn = self.valueInput
this optional binding is pointless because the outlet is connected reliably before viewDidLoad
is called.– vadian
Nov 16 '18 at 14:14
Yes
print(strPr
) before valueIn.text! = strPr
– canister_exister
Nov 16 '18 at 14:47
Yes
print(strPr
) before valueIn.text! = strPr
– canister_exister
Nov 16 '18 at 14:47
Delete this line
if let priceIn = self.valueIn Input {
– canister_exister
Nov 16 '18 at 14:52
Delete this line
if let priceIn = self.valueIn Input {
– canister_exister
Nov 16 '18 at 14:52
|
show 6 more comments
1 Answer
1
active
oldest
votes
These lines are wrong:
valueIn.text! = strPr
valueIn.text! = "11"
valueIn.text!
should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?
Not sure exactly how your variables are declared, but try something like this:
valueIn.text = "11"
Or, if strPtr is an Optional, try this:
if let strPr = strPr {
valueIn.text = strPr
print("New valueIn.text: (valueIn.text!)")
}
I have an error on the first line, it says "Initializer for conditional binding must have Optional type, not 'String'"
– Vitaliy Mckay
Nov 27 '18 at 17:42
@VitaliyMckay Remove the if let strPtr = strPtr { and last } then
– ppalancica
Nov 28 '18 at 10:42
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%2f53339241%2fcant-change-input-value-in-swift-4-2%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
These lines are wrong:
valueIn.text! = strPr
valueIn.text! = "11"
valueIn.text!
should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?
Not sure exactly how your variables are declared, but try something like this:
valueIn.text = "11"
Or, if strPtr is an Optional, try this:
if let strPr = strPr {
valueIn.text = strPr
print("New valueIn.text: (valueIn.text!)")
}
I have an error on the first line, it says "Initializer for conditional binding must have Optional type, not 'String'"
– Vitaliy Mckay
Nov 27 '18 at 17:42
@VitaliyMckay Remove the if let strPtr = strPtr { and last } then
– ppalancica
Nov 28 '18 at 10:42
add a comment |
These lines are wrong:
valueIn.text! = strPr
valueIn.text! = "11"
valueIn.text!
should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?
Not sure exactly how your variables are declared, but try something like this:
valueIn.text = "11"
Or, if strPtr is an Optional, try this:
if let strPr = strPr {
valueIn.text = strPr
print("New valueIn.text: (valueIn.text!)")
}
I have an error on the first line, it says "Initializer for conditional binding must have Optional type, not 'String'"
– Vitaliy Mckay
Nov 27 '18 at 17:42
@VitaliyMckay Remove the if let strPtr = strPtr { and last } then
– ppalancica
Nov 28 '18 at 10:42
add a comment |
These lines are wrong:
valueIn.text! = strPr
valueIn.text! = "11"
valueIn.text!
should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?
Not sure exactly how your variables are declared, but try something like this:
valueIn.text = "11"
Or, if strPtr is an Optional, try this:
if let strPr = strPr {
valueIn.text = strPr
print("New valueIn.text: (valueIn.text!)")
}
These lines are wrong:
valueIn.text! = strPr
valueIn.text! = "11"
valueIn.text!
should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?
Not sure exactly how your variables are declared, but try something like this:
valueIn.text = "11"
Or, if strPtr is an Optional, try this:
if let strPr = strPr {
valueIn.text = strPr
print("New valueIn.text: (valueIn.text!)")
}
answered Nov 17 '18 at 14:35
ppalancicappalancica
3,31341834
3,31341834
I have an error on the first line, it says "Initializer for conditional binding must have Optional type, not 'String'"
– Vitaliy Mckay
Nov 27 '18 at 17:42
@VitaliyMckay Remove the if let strPtr = strPtr { and last } then
– ppalancica
Nov 28 '18 at 10:42
add a comment |
I have an error on the first line, it says "Initializer for conditional binding must have Optional type, not 'String'"
– Vitaliy Mckay
Nov 27 '18 at 17:42
@VitaliyMckay Remove the if let strPtr = strPtr { and last } then
– ppalancica
Nov 28 '18 at 10:42
I have an error on the first line, it says "Initializer for conditional binding must have Optional type, not 'String'"
– Vitaliy Mckay
Nov 27 '18 at 17:42
I have an error on the first line, it says "Initializer for conditional binding must have Optional type, not 'String'"
– Vitaliy Mckay
Nov 27 '18 at 17:42
@VitaliyMckay Remove the if let strPtr = strPtr { and last } then
– ppalancica
Nov 28 '18 at 10:42
@VitaliyMckay Remove the if let strPtr = strPtr { and last } then
– ppalancica
Nov 28 '18 at 10:42
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%2f53339241%2fcant-change-input-value-in-swift-4-2%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
What do you mean by "it's not working"? Do you get a compile time error? What is the type of
valueIn
?– Daniel T.
Nov 16 '18 at 14:04
self.valueIn Input
— what does it even mean? It is not valid Swift.– user28434
Nov 16 '18 at 14:10
1
Show the code where
strPr
is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you meanif let priceIn = self.valueInput
this optional binding is pointless because the outlet is connected reliably beforeviewDidLoad
is called.– vadian
Nov 16 '18 at 14:14
Yes
print(strPr
) beforevalueIn.text! = strPr
– canister_exister
Nov 16 '18 at 14:47
Delete this line
if let priceIn = self.valueIn Input {
– canister_exister
Nov 16 '18 at 14:52