primer contacto con el entorno de...

31
PRIMER CONTACTO CON EL ENTORNO DE DESARROLLO Luis Montesano

Upload: others

Post on 18-Aug-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMER CONTACTO CON EL ENTORNO DE DESARROLLO

Luis Montesano ' Bob D/ Nvsjmmp

Page 2: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

INDICE PARA HOY• ¿Que vamos a aprender en este curso?

• Introducción a los conceptos básicos

• Programación

• Modelo MVC (Model-View-Controller)

• Introducción al entorno de desarrollo e instalación en los ordenadores

• Hello world para el iPhone

• Objective C

Page 3: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

CONCEPTOS BÁSICOS

• Programación orientada a objetos:

• Clase: un patrón para un objeto

• Instancia u objeto

• Mensaje: información enviada a un objeto

• Método: código que responde a un mensaje

• Herencia: estructura jerárquica de relación entre clases (y objetos)

• Subclase, superclase

• Herencia de funcionalidades entre clases

• Variable: almacenamiento de cada instancia (e.g. puntero a otro objeto)

• Protocolo (o Interfaz): conjunto de mensajes a los que un objeto responde

Page 4: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

Page 5: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

Page 6: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

Page 7: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

Nombre de la clase / Superclase

Page 8: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

Nombre de la clase / SuperclaseAtributos

Page 9: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSNumber *age;!}

-(void)setAge:(NSNumber *)myAge;-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

Include (resuelve las dependencias ciclicas)

Page 10: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

Métodos

Page 11: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

PRIMERA CLASE DE OBJECTIVE C

Métodos

-(void)setAge:(NSNumber *)age;

El método no tiene un nombre explícito. Se identifica solo por los argumentos.En este caso, el método tiene un solo argumento de tipo NSNumber * y llamado setAge

Page 12: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

PRIMERA CLASE DE OBJECTIVE C

Métodos

-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years;

Page 13: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(NSNumber *)getAge;

-(void)setSurname:(NSString *)sname;-(NSString *)getSurname;

-(void)setName:(NSNumber *)fname;-(NSNumber *)setSurname;

-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

Page 14: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C

#import <Foundation/Foundation.h>

@interface Student : NSObject {! NSString *name;! NSString *surname;! NSInteger *age;!}

-(void)setAge:(NSNumber *)myAge;-(NSNumber *)getAge;

-(void)setSurname:(NSString *)sname;-(NSString *)getSurname;

-(void)setName:(NSNumber *)fname;-(NSNumber *)setSurname;

-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years

@end

Funciones de lectura y escritura para los atributos

Page 15: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C#import "Alumno.h"

@implementation Student

//@synthesize name, surname, age, repeats, type,photo;

-(void)setAge:(NSInteger *)myAge{! age=myAge;}-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years Type:(NSString *)ctype{!! // Implementación de la inicialización! [objeto mensaje:argumento] [fname capitalize] // Poner en mayúsculas

return self;}

-(void)dealloc {! // Más adelante

}@end

Page 16: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C#import "Alumno.h”

@implementation Student

@synthesize name, surname, age, repeats, type,photo;

-(void)setAge:(NSInteger *)myAge{! age=myAge;}-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years Type:(NSString *)ctype{!! // Implementación de la inicialización! [objeto mensaje:argumento] [fname capitalize] // Poner en mayúsculas

return self;}

-(void)dealloc {! // Más adelante

}@end

Page 17: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

PRIMERA CLASE DE OBJECTIVE C#import "Alumno.h"

@implementation Student

@synthesize name, surname, age, repeats, type,photo;

-(void)setAge:(NSInteger *)myAge{! age=myAge;}-(id)initWithName:(NSString *)fname Surname:(NSString *)sname Age: (NSInteger*)years Type:(NSString *)ctype{!! // Implementación de la inicialización! [objeto mensaje:argumento] [fname capitalize] // Poner en mayúsculas

return self;}

-(void)dealloc {! // Más adelante

}@end

Page 18: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

¿QUE HACEMOS CON EL ALUMNO?

• Tenemos un alumno en el iPhone, ¿qué podemos hacer con el?

• Crear un interfaz de usuario para:

• Ver su información

• Modificar su edad

Page 19: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

MODELO VISTA CONTROLADOR

Controlador

Modelo Vista

Page 20: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

MODELO VISTA CONTROLADOR

Controlador

Modelo Vista

El modelo MVC separa la información de su representación, a través de un controlador

Controlador

Modelo Vista

Page 21: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

UN EJEMPLO SENCILLO: VISOR DE ALUMNOS

Controlador

Modelo Vista

Clase Alumno ?

?

Page 22: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

IB: INTERFACE BUILDER

Page 23: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

IB: INTERFACE BUILDER

Arrastrar

Page 24: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

IB: INTERFACE BUILDER

Page 25: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

IB: INTERFACE BUILDER

DEMOInstalar SDK para el iPhone

Page 26: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

UN EJEMPLO SENCILLO: VISOR DE ALUMNOS

Controlador

Modelo Vista

Clase Alumno Interfaz creado por IB

?

Page 27: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

EL PRIMER CONTROLADOR

#import <UIKit/UIKit.h>#import ”Alumno.h”

@interface MyViewController : UIViewController {! // Vista IBOUTLET UITextField *textField; ! IBOUTLET UILabel *label;

// Model (datos) Alumno *name;}

- (IBAction)showName:(id)sender;

@end

Page 28: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

EL PRIMER CONTROLADOR

#import <UIKit/UIKit.h>#import ”Alumno.h”

@interface MyViewController : UIViewController {! // Vista IBOUTLET UITextField *textField; ! IBOUTLET UILabel *label;

// Model (datos) Alumno *name;}

- (IBAction)showName:(id)sender;

@end

UIKit.h contiene UIViewController, la clase que da soporte a MVC

Page 29: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

EL PRIMER CONTROLADOR

#import <UIKit/UIKit.h>#import ”Alumno.h”

@interface MyViewController : UIViewController {! // Vista IBOUTLET UITextField *textField; ! IBOUTLET UILabel *label;

// Model (datos) Alumno *name;}

- (IBAction)showName:(id)sender;

@end

Nuestro controlador va a usar nuestro modelo de datos

Page 30: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

EL PRIMER CONTROLADOR

#import <UIKit/UIKit.h>#import ”Alumno.h”

@interface MyViewController : UIViewController {! // Vista IBOUTLET UITextField *textField; ! IBOUTLET UILabel *label;

// Model (datos) Alumno *name;}

- (IBAction)changeAge:(id)sender;

@end

Page 31: PRIMER CONTACTO CON EL ENTORNO DE DESARROLLOwebdiis.unizar.es/~anacris/curso_ios/0.Introduccion.pdf · INDICE PARA HOY • ¿Que vamos a aprender en este curso? • Introducción

UNA APLICACIÓN SIMPLE

COMPLETAR DEMO