Archive for category Regular Post

Solid Coding: Autoresize Masks

UITableView cell contains UILabel set with mask to pin the left and right and allow change to width

If the frame of the cell shrinks past the origin of the UILabel, then the right side of the label will be beyond the right side of the cell frame when it was previously contained entirely inside the frame.

This can be detected with Assertions in the ‘setFrame’ method or you can override the incoming frame to prevent the cell’s frame from shrinking so small that the expansion will be incorrect.

Images missing from iOS bundle

I was working on a “framework” for an iOS app.  When I added image resources, they did not work.

After Googling about for the answer, it seems that Apple added a setting for the MacOS framework template to combine related image files (like image.png and image@2x.png) into one multi-image TIFF file.  Since we based our product on that template, we had that setting. All the images were being put into files the iOS did not support.

If you have this problem, search your project for the “Combine High Resolution Artwork” setting (a.k.a. COMBINE_HIDPI_IMAGES). Be sure that it is set NO in all targets.

Why its hard to use auto-correct on the search bar…

One of the best QA people I have ever worked with caught something that really impressed me.  She was working on reports of crashes while touching cells in a UITableView which was the result of a search.  When the user would touch one of the cells, the app would sometimes crash.  She noticed that the crashes only happened IF autocorrect was showing when the user touched the cell AND the auto-corrected search string would produce no results.  (I really wonder if I would have noticed such a detail.)

As it turned out, once the auto-correct is showing, any touch that is not the keyboard or the auto-correct’s popup (for dismissal) then the touch is considered an “accept” of the suggestion.

The part of this that caused the crash was the combination and simultaneous nature of the events. The auto-correct is accepted first. This causes a change in the search results which are the data source for the table. But the touch is also processed for the UITableView. It results in a didSelect call for the index path originally touched.  This can result in an attempt to access something that no longer exists.

The quick and easy solution is to disable auto-correct on the search bar.  That prevents the whole mess.

But, it also shows that if the data source is not prepared for the possible attempt to use bad numbers, it could result in a crash. And are we really sure that some other subtle combinations of things won’t also result in bad numbers?

A final thought:  If you correct your code to handle the invalid indexPath after the change of search, assume there is a result that winds up with the same indexPath.  It probably will not be the same result that was there before. Now the user will think there is a bug and file a bug report.

 

When the iOS auto-correct will NOT appear…

Are you trying to make auto-correct give a suggestion, but it won’t appear?

Make sure to use the on-screen keyboard to do the typing.

It turns out that iOS knows if you are typing on the on-screen keyboard or a physical keyboard. If you are using a physical keyboard, it won’t present suggestions.

This held true for both the simulator and the device.  When I tested using the simulator, the keyboard on the computer would not cause suggestions.  When I tested using a bluetooth keyboard with an iOS device, it would not cause suggestions either.

IDE Feature Wish List – Adding Methods for Properties

This one comes from working with Xcode one version back from the latest (I still need to build for armv6) so the latest Xcode may already have it.

Xcode should help us manually add properties and their methods as easily as it adds them for IBOutlets in Interface Builder.

When we edit .XIB files, we can just drag connections over to the .h file in the assistant editor and a property will be added to the header. It will also add @synthesize lines and releases in both dealloc and viewDidUnload.

Why can’t Xcode do that when we add properties that are not IBOutlets?

IDE Feature Wish List – Programmer Popup Descriptions

More things for the IDE (Integrated Development Environment).  Xcode is the one I use for iPhone development,  so hint, hint Apple.

Like a desktop program or web page allows you to hover the mouse pointer over something to get information about it, the IDE should give me more information about a variable when I make a gesture for it.

Now Xcode already has some hover information for some things.  It shows the type and some contents of a variable.

What I’m talking about is giving developers the ability to see information they have set about a variable.

It would also be great to have quick access to documentation, known bugs, easy mistakes to make, valid value ranges, etc.

It would be better than having to track down the definition somewhere in the header files or source files to see if (maybe) someone put a comment by it.

It might also encourage developers to write more and better comments.

XCode 4 Column-Wise Copy-Paste Changed – Update

By accident today, I found that the built-in application TextEdit still supports column-wise copy-paste operations the way I liked them in old versions of Xcode.

I had copied a column of numbers from Xcode and pasted it into a document assuming that TextEdit would just paste it in linearly and I would fix up the format afterward.

SURPRISE!  It pasted in columnar fashion just like Xcode once did.  It made short work of my editing.

A quick test showed that I can hold the option key and copy in columnar fashion as well.

Neither Xcode nor TextWrangler can paste this way.

TextEdit just got more valuable to me for doing work.

My previous blog post on this matter.

Tags:

IDE Feature Wish List – Spell Check Comments

More things for the IDE (Integrated Development Environment).  Xcode is the one I use for iPhone development,  so hint, hint Apple.

 Check Spelling Inside Comments
This a useful feature, really.  I often use the TextEdit application that came with my Mac and it will auto-correct while I type.  On average, this is a big plus when my fingers get a little out of order and transpose two letters.
Since the comments are about the written communication from one human developer to other human developers, having spell-check is really important.
See my previous posts that talk about having comments written in RTF so we can communicate with more than plain text.  (Why are we still stuck with plain-text source files in 2012?)

Tags: , ,

What the IDE ought to do for us

Over time, I write down ideas I have for things.  Here are some for the IDE:

  • Allow you to specify what builtin types are expected for the code being built.
    • When they are not the expected sizes or signs, you get a warning or error.
    • Example:  if the code specifies that ‘int’ should be a 32-bit signed integer, but the compiler is set to treat it as a 16-bit signed integer, you get a compile error.
    • When targeted hardware does not support the expected types and sizes, you get an error.
  • IDE should tell you what the result of a macro will be.
    • What will the value of a #defined macro be at each point in the code.
    • Grey-out or visually indicate  that code will compile out of the result.
  • Mix code and RTF documentation.  That way, the code can have real documentation mixed into it.  You could code up the new API and just above it is documentation with fonts, bold, underline, etc.  Then you can extract this nicely formatted text and drop it straight into documents of various word-processing applications.
  • Should compile on-the-fly and as-you-type and tell you succeed or fail immediately on completing a line.
  • Should auto-indent and code-fold all the current ways, plus:
    • Fold based on conditional compile logic. (Fold everything between #ifdef and #else and #endif, etc.  That can get lots of legacy code for other platforms out of sight.
    • Fold comments and documentation.
  • Cut and paste vertical columns. (That’s paste vertically into a column as well.)

 

Finder window showing blank white page for home directory

Weird stuff.  My home folder has been just showing a blank white page lately.   Whenever I make a new window,  its just white.

If I scroll up or down, everything appeared.  If I typed the name of something and hit Command-O  or command-down-arrow it would open just fine.

Since I touch-type and use keyboard shortcuts a lot, it hasn’t gotten in the way, but it has been worrisome.

Just a few minutes ago I recalled an old memory that Finder would only store some settings when you close a window with the red chicklet button.

I opened a new window, scrolled to make things show up, selected a subfolder and closed with the button.  Now all my new windows show things properly again.