Archive for the ‘Apple’ Category

Customizable UIPageControl Clone

Sunday, August 1st, 2010

I'm working on a project that requires to use UIPageControl. The catch? White background. With UIScrollView you can choose between white and black indicators, with UIPageControl no luck — only white dots.

But it turns out that UIPageControl is not that complicated. I've opened its definition, copied it, added dots color property and implementation. Now I have a drop-in replacement for UIPageControl and free to choose any color for the dots.

ZZPageControl

Sample project with ZZPageControl class is available in SVN repository. If you spot any problems with it please contact me!

A few things iOS developers ought to know about the ARM architecture

Monday, July 19th, 2010

Many iOS developers just take advice on optimizing their code for specific architectures without investigating details, like use this option in this case and that option in that case. Here is a great article that clarifies details of ARM for Apple's devices: A few things iOS developers ought to know about the ARM architecture.

Bug In Split View-based Application Template

Monday, July 12th, 2010

When you create a project using this template you get two controllers. One of them is DetailViewController that shows details of the selected item and also manages popover with items list. I've discovered that there is a subtle bug, and it hits you when you show another view controller modally.

Seems to be a rare case but I was showing registration screen, not that exotic feature!

How does it look like? Application loads and pulls data over the net to populate items list. When items list is ready the first item is set selected and shows in details controller. At this moment registration screen mysteriously disappears. Here is the code that updates details controller:

- (void)setDetailItem:(id)newDetailItem {
    if (detailItem != newDetailItem) {
        [detailItem release];
        detailItem = [newDetailItem retain];

        // Update the view.
        [self configureView];
    }

    if (popoverController != nil) {
        [popoverController dismissPopoverAnimated:YES];
    }
}

When I stopped in debugger it became obvious: dismissPopoverAnimated: was called and it just dismisses the current modal view controller! So the fix is to check whether the popover is actually visible, and what interesting is that there is a property for this: popoverVisible. Here is the fixed version of the method:

- (void)setDetailItem:(id)newDetailItem {
    if (detailItem != newDetailItem) {
        [detailItem release];
        detailItem = [newDetailItem retain];

        // Update the view.
        [self configureView];
    }

    if (popoverController && popoverController.popoverVisible) {
        [popoverController dismissPopoverAnimated:YES];
    }
}

The morale of the story: be precise when writing your code; avoid side-effects.