Friday, March 19, 2010

Accessing Unknown 'backgroundColor' Component of a Property

Embarrassing problem. Forgot to import the header file or add class forward declaration. Somehow you'd expect those to happen automatically, don't you think?

Code works as-is right after import has been done. Just adding this reminder for google to find next time.

Tuesday, March 16, 2010

Changing Name of "Edit" UIBarButtonItem

If you use default UIToolbar "Edit" button provided by Interface Builder, you cannot change the name from code. You have to change UIBarButtonItem identifier to "Custom" and title as "Edit". Then add this delegate code:

- (IBAction)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [self.myController.myView setEditing: !self.myController.myView.editing animated:YES];
    if (self.myController.myView.editing)
    {
        self.editButton.title = @"Done";
        self.editButton.style = UIBarButtonItemStyleDone;
    }
    else
    {
        self.editButton.title = @"Edit";
        self.editButton.style = UIBarButtonItemStyleBordered;
    }
}
Don't forget to hardcode button width at 43 pixels, otherwise change of button title will shift position of following items on toolbar. That 43 pixels is the default width of standard Edit button and wide enough to show longer "Done" text string.

Monday, March 15, 2010

Interface Builder cannot change UIView color

If you fail to change UIView color in Interface Builder, it could be because Emulator is blocking your changes. Close emulator and try again.

Thursday, March 4, 2010

Unversioned Directory Already Exists in SVN Repository

SVN error note "Failed to add directory 'trunk/build': an unversioned directory of the same name already exists" means that your locally ignored directory has been added under version control. Maybe someone else did it, maybe you did it initially before deciding to ignore.

The fix is to remove those directories from version control. There's nothing you can do locally to fix it, you have to access the main, common, shared repository in network. Remove the directories, do refresh and updates.

Reminder how to ignore directories locally: go to folder (trunk), which contains directory (build) you want to ignore. Do command line "svn propedit svn:ignore" and make sure your list contains all the directories to be ignored.

If that command doesn't work (bash), define your editor as "export EDITOR=emacs" or whatever is your favorite editor. Control-x Control-c exits from emacs, in case you get stuck.

svn status, svn update and svn cleanup might help, too. Remember to read SVN manual BEFORE using any of those commands. You have been warned, all caused problems are own own responsibility.

Monday, March 1, 2010

How to Create a Black Statusbar

When you open MainWindow.xib in Interface Builder, you can find "Window - Status Bar" and "MainViewController - Status Bar". Setting either one or both as "Black" doesn't seem to have any effect on the actual application. Your statusbar remains gray.

So how do I get a black statusbar?

Open your application .plist file, click on plus icon (+) to create a new row and write "Status bar style" as name and select "Opaque black style" as value.

Those are "key = UIStatusBarStyle" and "string = UIStatusBarStyleOpaqueBlack if you're more familiar with that style.

Thursday, February 25, 2010

How to Disable UIWebView Selection

You could do this by running a short javaScript line at webViewDidFinishLoad, but I find this more elegant: define UIWebView properties in CSS.
NSString *myHtml = [NSString stringWithFormat:
   @"<html><head>"
   "<style type=\"text/css\">"
   // Disable Open/Copy/Cancel alert with long link selection
   "* {"
   "-webkit-touch-callout: none;"
   // Disable selection/Copy of UIWebView
   "-webkit-user-select: none;"
   "}"
   ",</style>"
   "</head><body>%@</body></html>", message.body];
[myWebView loadHTMLString:myHtml baseURL:nil];
As a bonus I left there also how to disable link selection popup.

Monday, February 22, 2010

How to Clear UITabBar badgeValue

It's delightfully easy to add a badgeValue into a UITabBarItem, but I couldn't find how to remove it. Turned out it's as easy as adding one:

if (count)
    self.parentViewController.tabBarItem.badgeValue = @"!";
else
    self.parentViewController.tabBarItem.badgeValue = nil;
Thanx Apple for these delightful surprises!