This is the 3rd and final part of the challenge app for Lesson 3 of Udacity's UIKit Fundamentals I course for their iOS Developer Nanodegree. This piece was so simple that I thought about just including in my previous post but decided to make another very small, short post about it. As a refresher here is my UI on initial load. Since this textfield also interacts with another control I decided to just use the primary view controller as the UITextFieldDelegate, instead of creating a different class like I did for the other two textfields. Here is my entire view controller for this storyboard. As you can see there isn't much there. I didn't change the keyboard type for this textfield because there isn't any kind of limit on what can be entered into the textfield. Since I had an outlet reference to the switch I simply returned the value of the switch at line 32. If the switch is on then text can be entered, if the switch is off then no text can be entered and also no text can be removed. The textfield is completely locked with the switch in the off position. I could have created an outlet action for the value changed event of the switch and then set the enabled property of the textfield but since the challenge was to work with UITextFieldDelegates I decided not to do that. Just for reference here is the same view controller with the delegate logic commented out and using a switch action instead. The left side is the app with the switch on and textfield enabled. The right side is switch off and textfield disabled. If you like the look of the disabled textfield you could also expand the delegate method and at line 31 of the second screen shot add textField.enabled = lockedSwitch.on; I just choose not to do that. I hope you enjoyed this short series on working with UITextFieldDelegates. My current plan is to continue write up small, short posts as I go through each lesson within each course and then create another post(s) for the project that I will submit for each course. That is my plan, but we'll see how well I follow through with that.
Here is my github repo for this specific work. https://github.com/swernimo/iOS/tree/master/UI%20Kit%20Fundamentals%201/Text%20Delegate%20Challenge. Check out all my repos and follow allow with me as I learn Swift. Good luck and happy coding. Sean Wernimont The Blind Squirrel Copyright 2015-2020
|
AuthorWelcome to The Blind Squirrel (because even a blind squirrel occasionally finds a nut). I'm a full-stack web and mobile developer that writes about tips and tricks that I've learned in Swift, C#, Azure, F# and more. Archives
April 2018
Categories
All
|