jump to navigation

What’s a UITextEffectsWindow? And why is it receiving messages? 17 September 2009

Posted by ojmason in Apple, iphone, objective-c, programming.
trackback

I just spent several hours (or at least it felt like several hours!) in frustration, searching a trivial bug. I’ve been testing a quick’n'easy prototype screen with an UIImageView and four UIButtons. The buttons are linked via an action to a view controller. And every time I press a button, my app conks out complaining that -[UITextEffectsWindow buttonPressed:] was an unrecognised selector. I checked the memory address, and it said it was my view controller, just before that exception was thrown.

I was ready to put the blame on some mistakes with Interface Builder, until I came across the solution (indirectly) in a blog: here the problem described related to properties, and the difference between “vc = …” and “self.vc = “. I had another look at my code and quickly found the offending line: I had the view controller as a local variable in the app delegates viewDidLoad method, and I autoreleased it. In other words, by the time the button was pressed the view controller no longer existed, and hence I got that weird error message.

This was not helped by the fact that UITextEffectsWindow is not mentioned in the documentation anywhere, as it seems to be an internal UIKit class, but at least it appears to be consistent.

So, if your button presses send messages to UITextEffectsWindow, make sure to check that your view controller is still alive!

Comments»

1. Chris Wild - 17 September 2009

You got to be careful with those properties, The number of times I’ve forgot to add the self. and hit problems. The answer is to have a different name for your variable than your property, that way you get into the habit of using the property name because it’s the one that makes sense.

eg.

NSString* _hiddenVariable;

Property (retain) NSString* Name;

@Synthesize Name = _hiddenVariable;

The only thing to remember when doing this is to add IBOutlet when needed to the property and not the variable declaration. Otherwise Interface Builder will pick up your variable and not the property.