|
Below is my code for the Multiplication Quiz challenge. What I don't like about it is how the TextField behaves. I've read numerous articles, but I can't find a way to make a TextField bound to an Integer value do the following:
Any insights on how to make SwiftUI's TextField behave in a "normal" manner (i.e., as a user would expect) would be appreciated!
|
|
|
|
|
|
Jeff has more questions:
To be honest? I've been chided about this before. So I hesitate to mention it. (See -> Obelix's Methods aren't Welcoming) I honestly didn't give your code a thorough review. Why? Because you provided too much code that has nothing to do with your problem. I disagree with others who posted the idea below (and apparently complained to @twoStraws):
I disagree with this idea. If you have problems formatting a Then show the code that doesn't work! While others have given me a hard time for stating this, I see great value in this idea. First, you're sharing your education with others, me included. (Unlike, ahem! some others...) Next, I see what you've tried; so I won't waste time suggesting non-working solutions. Also, I can look at your code and, perhaps, uncover syntax or malformed code. Finally, you get to post solutions that others will certainly use in the future. But, crivvens mate! You've included so much unrelated code, it's hard to see the specific codes what be ailin' yer heart. Help us to help you. PS: If you want to marvel at another example, See -> How to Toggle a Boolean with a Button? |
|
Ok, I see that from your perspective. The code I posted actually works, but I'm looking for alternate code that works better. "Better" would be: 1) Cursor blinking in the textfield on initial display; 2) When the field is committed, set the bound variable back to zero and have that change reflected on screen (currently, the previously-entered value persists); 3) Show a numeric keypad that contains a return key so the user can commit the value entered (I can't find such a keyboard). I do appreciate your help, and per your request, here is some trimmed-down code that demonstrates the issues I mentioned in as few lines as possible, with the requests above repeated in comments.
|
|
I find that when using So what I would do now is using |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.