PRIMER CONTACTO CON EL ENTORNO DE...
Transcript of PRIMER CONTACTO CON EL ENTORNO DE...
![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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/1.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/2.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/5.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/6.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/7.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/9.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/11.jpg)
#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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/12.jpg)
#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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/13.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/15.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/16.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/17.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/18.jpg)
¿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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/19.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/20.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/21.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/22.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/23.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/24.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/25.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/26.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/27.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/28.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/29.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/30.jpg)
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](https://reader036.fdocuments.co/reader036/viewer/2022063009/5fc03b2750836a66363e59b4/html5/thumbnails/31.jpg)
UNA APLICACIÓN SIMPLE
COMPLETAR DEMO