jueves, 8 de marzo de 2012

Método para calcular los días, horas, minutos y segundos que faltan entre la fecha actual y otra futura


- (void) tiempoHasta:(NSString *) hasta {
    
    // Fecha actual
    NSDate *date = [NSDate date];
    int secondsNow =(int)[date timeIntervalSince1970];
   
    // Convierto el string hasta 
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyyMMdd"];
    NSDate *hastaDate = [dateFormat dateFromString:hasta]; 
    
    int secondsTarget=(int)[hastaDate timeIntervalSince1970];
    int differenceSeconds=secondsTarget-secondsNow;
    int days=(int)((double)differenceSeconds/(3600.0*24.00));
    int diffDay=differenceSeconds-(days*3600*24);
    int hours=(int)((double)diffDay/3600.00);
    int diffMin=diffDay-(hours*3600);
    int minutes=(int)(diffMin/60.0);
    int seconds=diffMin-(minutes*60);
}

jueves, 23 de febrero de 2012

Iconos para nuestra App

Conviene que el icono de nuestra aplicación lo hagamos de 512 x 512 pixels porque cuando subamos la aplicación a la AppleStore nos va a pedir una imagen de ese tamaño.
Además deberíamos crear imágenes con los siguientes tamaños para los distintos dispositivos:

Iphone: 57 x 57 pixels 
High Resolution Iphone/Ipod: 114 x114 pixels
Ipad: 72 x 72 pixels
High Resolution Ipad: 144 x 144 pixels

miércoles, 8 de febrero de 2012

Crear un botón por código

// Creo el boton y lo inicio con un frame que creo con la funcion CGRectMake.
UIButton *reservaButton = [[UIButton alloc] initWithFrame:CGRectMake(230, 45, 76, 25)];

// El boton tiene una imagen, la agrego como background
[reservaButton setBackgroundImage:[[UIImage imageNamed:@"reservar.png"] 
 stretchableImageWithLeftCapWidth:75.0 topCapHeight:0.0] 
                         forState:UIControlStateNormal];

// Enlazo el boton con el método reserve
[reservaButton addTarget:self 
                  action:@selector(reserve:)   
        forControlEvents:UIControlEventTouchUpInside];


martes, 31 de enero de 2012

Agregar pin a un mapa

Lo conveniente es crear una nueva clase que llamaremos Pin:
Pin.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>

@interface Pin : NSObject{ 
    CLLocationCoordinate2D coordinate;        
    NSString *subtitle;        
    NSString *title;     
}
    
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic,retain)NSString *subtitle;
@property (nonatomic,retain) NSString *title;
- (id) initWithCoords:(CLLocationCoordinate2D) coords;

@end 

Pin.m
#import "Pin.h"
@implementation Pin
@synthesize coordinate;
@synthesize subtitle;
@synthesize title;

- (id) initWithCoords:(CLLocationCoordinate2D) coords{

    self = [super init];
    
    if (self != nil)
        coordinate = coords;
    
    return self;
}

- (void) dealloc{
    [title release];
    [subtitle release];
    [super dealloc];

}
@end


Luego agregamos al mapa el pin:
CLLocationCoordinate2D pinlocation;
pinlocation.latitude = latitude;
pinlocation.longitude  = longitude;
Pin *pin = [[Pin alloc] initWithCoords:pinlocation];
pin.title = self.tituloSel;
[mapa removeAnnotations:[mapa annotations]];
[mapa addAnnotation:pin];
[pin release];

miércoles, 18 de enero de 2012

Mostrar otra pantalla

self.infoController = [[InformationViewController alloc]
                      initWithNibName:@"InformationViewController" 
                               bundle:[NSBundle mainBundle]];
 
[self presentModalViewController:infoController animated:YES];


y para volver desde esa nueva pantalla

  [self dismissModalViewControllerAnimated:YES];

Otra forma de pasar a otra pantalla
  progressView = [[ProgressViewController alloc] initWithNibName:@"ProgressViewController" bundle:nil];
        [self.view addSubview:progressView.view];