Tip Calculator App: How to make the $ permanent in the textfield?


#1

This is a small question and probably a simple answer, but I haven’t had luck searching online for it (probably because the words are too general and common).

For the tip calculator app from the 4-part free course, I understand that the dollar sign ($) is needed in the textfield, for the app to calculate currency.

I have the app starting with the dollar sign in the textfield, so that’s fine; the only problem is that the delete button on the UI keyboard can be used to delete the dollar sign, and then the app won’t do any calculations at all.

So I’d like to make the dollar sign permanent (i.e. not able to be deleted). Anyone know a good way to do this?


#2

Were you able to figure it out?

You’ll need to look at each key as it’s typed, and then you can evaluate if it should be able to modify your text.

UITextField Text Editing Changed Events

And you can read the related write-up and get code samples here:

Taking it a step further, there are some additional APIs that you can use to hook in, and then prevent the $ from being removed.