Thursday, April 29, 2010

Multiline UIButton Title

Some things are really easy with iPhone SDK - eventually. For example if you want to have a non-custom UIButton with multiline title:

Write button title in "Title" field. When you want to have a linebreak, press Alt-Return. Then set "Line Breaks" as Character Wrap or Word Wrap. Done!

(Using Interface Builder)

Monday, April 26, 2010

How to Get Rid of Keyboard with a Tap on Background

There is a screen with a couple of UITextFields and UIButtons. When user taps on UITextField, keyboard popups. Very nice of iPhone SDK to provide such a feature! Each UITextField and UIButton is a clickable object with easy callbacks.

But how do you get rid of keyboard?

Should you have a special "Please hide keyboard" button or tap into accelerometer to notice when user gets desperate enough to start shaking the device? There's an easier way...

Add a full-screen empty non-editable UITextView over the whole screen. Select each clickable object e.g. UITextField, UIButton or other UITextViews and use Interface Builder menu item Layout - Send to Front to place them on top of your full-screen UITextField.

When user clicks on anywhere except your clickable objects, keyboard disappears. What a relief!

Please note that, if you leave any non-clickable objects e.g. UILabel on top of your full-screen UITextView, clicking on those spots will not hide keyboard.

Friday, April 23, 2010

UITableView doesn't scroll

This makes no sense, but seems like (in Interface Builder) your UITableView must have Scroll View section item Delay Content Touches checked.

Otherwise your table doesn't scroll by touch events.

Why doesn't my graphics change when I edit them

Problem with branching and merging is that graphics files might change physical location. Xcode won't complain anything at all, as long as it can find some copy of the file.

Check if you have several copies of same file e.g. under project root and inside classes folder. Find out which one is being used, remove the other one(s) and fix version control to contain only one copy of the file.

Agree common location for all graphics files, regardless if they are used only within one of several modules in project.

Thursday, April 15, 2010

Problems removing breakpoints

If Xcode refuses to remove breakpoints, first close simulator and then save the source code file. After that Xcode starts to co-operator and nicely removes the breakpoint.