The default behavior for a UITextField on pressing the return key is to execute the textFieldShouldReturn: method of the UITextFieldDelegate.
What if we wanted to create similar behavior with a a UITextView which does not have an equivalent method and by default just creates a new line?
Nick Dalton has come up with a snippet of code that uses the:
method of the UITextViewDelegate to do just that.
You can check the article out here: Handling The Return Key In A UITextView
It’s a very handy bit of code to have as there are many situations where you may want to implement custom behavior when the return key is pressed in a UITextView.
Please post any comments below, thanks.
I was looking through the searches on this site trying to think of what to post about today, and i noticed that, surprisingly to me one of the top searches has consistently been for information on the model-view-controller (MVC) design pattern. Maybe I shouldn’t be surprised though as this is a pattern that Apple often follows in their libraries, and examples, and is mentioned quite frequently.
A few months ago I posted a video where I gave a rudimentary explanation of MVC, and a method for coming up with some possible class names when developing an app.
You can see this video here:
In summary, MVC is simply this:
A design pattern in which the model (any data in your program), the view (what the user sees), and the controller (a layer that handles all interaction between the view and model) are separated in such a manner that modifying either the view or model component of your program has no effect on one another.
The purpose is that later on you may need to change your programs view, and by programming things in this matter you will not have to modify your programs model. Say for instance Apple comes out with an iPad for which the view is programmed somewhat differently than on the iPhone, but you would like to
Now I received some messages after making the video above, some thanking me for making the concept of MVC sound so simple, and others telling me that I had confused them, and wondering how I could understand any of this stuff.
Well, don’t fret.. I’ve seen arguments all over the place as to what components should be classified in the model, the view, or the controller, and I’ve even seen accomplished "guru authors" mess things up when explaining what goes where, just keep in mind that the key idea here is that you can modify one of these key areas without completely wrecking another key area of your program, and leave the rants to the wannabe coders who like to argue about what exactly what fits what acronym, and MVC is often their target.
Something that can be very easily done using Cocoa Touch is animation. This is a brief programming tutorial showing how it’s done.
The easiest way to do animation in Cocoa Touch is using the animationImages property from a view.
It’s a simple 3 step process.
1. Set animation images to an array containing your UIImages to be used for animating.
2. Set the duration to animate for. (you can also set the number of times to repeat the animation for.)
3. Start the animation.
UIImageViewName.animationImages = arrayContainingImages
UiImageViewName.animationDuration = .. number of seconds ..
More information on animationImages can be found in Apple’s UIImageView Class Reference here.
Brandon has posted a nice project here at: Animating A Game Sprite