Tagged
iOS


Link
iOS MapKit: Custom CallOut using a Pop Over

I saw this customized callout and tried lurking stackoverflow (actually I did ask the question) on how to create a customized callout (the speech bubble the appears when you touch the pins/annotations. Normally, you can only get an image or two and two lines of text, namely the Title and Subtitle in the callout, and sometimes you need more informations displayed.

but first, on to the creation of Custom pins:

- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation

{

    if ([annotation isKindOfClass:[MKUserLocation class]])

        return nil;

    static NSString* AnnotationIdentifier = @”AnnotationIdentifier”;

    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];

    if(annotationView)

        return annotationView;

    else

    {

        UIImage *img = [UIImage imageNamed:@”default_thumb.png”];

        MKAnnotationView *annotationView = 

            [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];

        annotationView.canShowCallout = YES;

        annotationView.image = img;

        annotationView.draggable = YES;

        /*

        // change left accessory view button with image

        UIImageView *leftAccView = [[UIImageView alloc] initWithImage:img];

        annotationView.leftCalloutAccessoryView = leftAccView;

        //include a right button to show more info         

        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

        [rightButton addTarget:self action:@selector(calloutSubMenu:) forControlEvents:UIControlEventTouchUpInside];

        [rightButton setTitle:annotation.title forState:UIControlStateNormal];

        annotationView.rightCalloutAccessoryView = rightButton;         

         */

        return annotationView;

    }

    return nil;

}

here, the image imported (default_thumb.png) is shown instead of a regular pin done by overriding - (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation and using the image you want to use. The extra code commented out changes the left callout accessory button into UIImage instead of a regular UIButton for the callout’s accessory view. Same thing can be done to the right accessory button.

On to the Custom Callout:

First you create a subclass of UIViewController (mine uses a xib to skip the extra coding).

In the xib , add the necessary contents to display in your callout.

// Override viewing of the annotation’s callout

-(void)mapView:(MKMapView *)mapview didSelectAnnotationView:(MKAnnotationView *)view

{

    [mapView deselectAnnotation:view.annotation animated:YES];

    PopOverCallout *popOverCallout = [[PopOverCallout alloc]init];

    UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:popOverCallout];

    self.annotationPopoverController = popOver;

    popOver.popoverContentSize = CGSizeMake(200, 70);

    [popOver presentPopoverFromRect:view.bounds inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

}

In your controller with the Map View, override (void)mapView:(MKMapView *)mapview didSelectAnnotationView:(MKAnnotationView *)view method subclass.

Inside the method, create a UIPopoverController initialized with the your subclass (the PopOverCallout is the UIViewController subclass you made).

store the new popover controller into an instance variable.

set the size popover which is from the upper-left corner of the xib of the UIViewController subclass.

finally the last line initializes the properties of your popover.

I’ll probably edit this post later to make things easier to understand… or not. Anyways, that’s that.

06:35 pm: laevatein1 note

Link
iOS Tutorials

bunch of simple and detailed tutorials using xcode 4 and the ios 4 simulator.

12:56 pm: laevatein4 notes

Link
iOS development: First impressions

I’m getting a hang of doing it but I’d say it’s not really that easy.

Coming from c# and .NET using Visual Studio, I’d say it’s not really comfortable programming using Objective-C, both syntax and memory management-wise.

Another point is about Xcode. Sure it has “kinda similar” intellisense but the UI isn’t intuitive enough and no feature that could test the emulation of GPS (They do have it now in iOS 5 SDK but why not have it way back when GPS feature is added?) unlike microsoft which tossed those in for free (wasn’t included in windows mobile 6 sdk but at least there was an open source tool).

There might be pros and cons but I guess I’m seeing more of the cons… for now.

EDIT: I take the “UI isn’t intuitive enough”… and replacing it with “Xcode UI isn’t intuitive at all”. Changing font styles for the control texts isn’t even in the right window pane along with the other UI options and needs to be opened via menu. I hope the new xcode release has this functionality added already. Loyal xcode users are martyrs for overlooking this >.>

12:10 pm: laevatein6 notes

Link
Giving Objective-C 2.0 and iOS development another chance

since I can’t see windows phone beating iOS and android anytime soon with apps and software upgrades, might as well try it. 

10:52 am: laevatein2 notes

Link
Trying out iOS development

When I read about Objective C being the language used for ios apps, I immediately thought “hey, C is pretty easy. I could take that on”.

After checking out a few videos about objective C, I’d say it’s not what I really thought it would be with all the ‘@’ signs, brackets everywhere and NS class names. Not to mention Xcode isn’t as friendly as the usual IDE like eclipse, netbeans or visual studios.

I still managed to figure out how to change a label text using a button, at least. I guess it’s not as easy coming from .Net stuff and Visual studios. It should be pretty interesting and I hope I get used to Xcode, Interface Builder and Objective-C pretty soon.

So much for the friendly, boring, darn easy ‘Hello world!’.

06:31 pm: laevatein1 note