formacion en movilidad: conceptos de desarrollo en ios (iii)

43
Televisió de Catalunya Formación en movilidad Conceptos de desarrollo en iOS 3ª sesión mayo 2013 1

Upload: mobivery

Post on 09-May-2015

247 views

Category:

Technology


0 download

DESCRIPTION

En esta tercera sesión formativa, impartida por Sergi Hernando, CTO de Mobivery, se trataron los siguientes conceptos: UIWebView, View Cotroller en iPad y el Simulador

TRANSCRIPT

Page 1: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

Televisió de CatalunyaFormación en movilidad

Conceptos de desarrollo en iOS3ª sesión mayo 2013

1

Page 2: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

Qué veremos hoy

Repaso de la sesión anterior

UIWebView

View Cotroller en iPad

Simulador

2

Page 3: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

Recursos

Tutoriales de Ray Wenderlichwww.raywenderlich.com/tutorials

Cursos de Stanford en iTunes Uitunes.stanford.edu

iOS Developer Librarydeveloper.apple.com/library/ios

3

Page 4: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

RepasoView Controller

UIViewController

4

Page 5: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

RepasoNavigation Bar

UINavigationItemUIBarButtonItem - NSString - UIBarButtonItem

5

Page 6: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

RepasoUIBarButtonItem

self.navigationItem.rightBarButtonItem

6

Page 7: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

RepasoUIStoryboardSegue

Modal

7

Page 8: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

Repaso// MasterViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([[segue identifier] isEqualToString:@"newDetail"]) {! ! NewVideoViewController *viewController = (NewVideoViewController *)[segue destinationViewController];! ! viewController.masterViewController = self;! }}

8

Page 9: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

Repaso// NewVideoViewController.m

- (IBAction)done:(id)sender {! [self dismissViewControllerAnimated:YES completion:^{! ! NSDictionary *values = @{! ! ! @"title": self.videoTitle.text, @"author": self.videoAuthor.text, @"url": self.videoURL.text! ! };! ! [self.masterViewController insertNewObject:values];! }];}

9

Page 10: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

Repaso// MasterViewController.m

- (void)insertNewObject:(NSDictionary *)values{ // ... [newManagedObject setValue:[NSDate date] forKey:@"timeStamp"]; [newManagedObject setValue:[values objectForKey:@"title"] forKey:@"title"]; [newManagedObject setValue:[values objectForKey:@"author"] forKey:@"author"]; [newManagedObject setValue:[values objectForKey:@"url"] forKey:@"url"]; // ...}

10

Page 11: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

Debugging

11

Page 12: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebView

// DetailViewController.h

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate, UIWebViewDelegate>

@property (strong, nonatomic) id detailItem;

@property (nonatomic, weak) IBOutlet UILabel *titleLabel;@property (nonatomic, weak) IBOutlet UILabel *authorLabel;@property (nonatomic, weak) IBOutlet UIWebView *webView;

@end

12

Page 13: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebView

// DetailViewController.m

- (void)configureView{ // ... self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"];}

13

Page 14: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebView

// DetailViewController.m

- (void)configureView{ // ... self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"];

NSURL *theURL = [[NSURL alloc] initWithString:[self.detailItem valueForKey:@"url"]]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theURL];

[self.webView loadRequest:request];}

14

Page 15: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebViewUIWebViewDelegate

// DetailViewController.m

- (void)configureView{ // ... self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"];

NSURL *theURL = [[NSURL alloc] initWithString:[self.detailItem valueForKey:@"url"]]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theURL];

[self.webView setDelegate:self]; [self.webView loadRequest:request];}

15

Page 16: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebViewUIWebViewDelegate

// DetailViewController.m

- (void)configureView{ // ... self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"];

NSURL *theURL = [[NSURL alloc] initWithString:[self.detailItem valueForKey:@"url"]]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theURL];

[self.webView setDelegate:self]; [self.webView loadRequest:request];}

#pragma mark - UIWebViewDelegate

- (void)webViewDidStartLoad:(UIWebView *)webView {}

- (void)webViewDidFinishLoad:(UIWebView *)webView {}

16

Page 17: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebViewUIActivityIndicatorView

// DetailViewController.h

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate, UIWebViewDelegate>

@property (strong, nonatomic) id detailItem;

@property (nonatomic, weak) IBOutlet UILabel *titleLabel;@property (nonatomic, weak) IBOutlet UILabel *authorLabel;@property (nonatomic, weak) IBOutlet UIWebView *webView;@property (nonatomic, strong) IBOutlet UIActivityIndicatorView *spinner;

@end

17

Page 18: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebViewUIActivityIndicatorView

// DetailViewController.m

- (void)configureView{ // ... self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner.center = self.view.center;

NSURL *theURL = [[NSURL alloc] initWithString:[self.detailItem valueForKey:@"url"]]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theURL];

[self.webView setDelegate:self]; [self.webView loadRequest:request];}

#pragma mark - UIWebViewDelegate

- (void)webViewDidStartLoad:(UIWebView *)webView {}

- (void)webViewDidFinishLoad:(UIWebView *)webView {}

18

Page 19: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebViewUIActivityIndicatorView

// DetailViewController.m

- (void)configureView{ // ... self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner.center = self.view.center;

NSURL *theURL = [[NSURL alloc] initWithString:[self.detailItem valueForKey:@"url"]]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theURL];

[self.webView setDelegate:self]; [self.webView loadRequest:request];}

#pragma mark - UIWebViewDelegate

- (void)webViewDidStartLoad:(UIWebView *)webView { dispatch_async(dispatch_get_main_queue(), ^{ });}

- (void)webViewDidFinishLoad:(UIWebView *)webView {}

19

Page 20: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebViewUIActivityIndicatorView

// DetailViewController.m

- (void)configureView{ // ... self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner.center = self.view.center;

NSURL *theURL = [[NSURL alloc] initWithString:[self.detailItem valueForKey:@"url"]]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theURL];

[self.webView setDelegate:self]; [self.webView loadRequest:request];}

#pragma mark - UIWebViewDelegate

- (void)webViewDidStartLoad:(UIWebView *)webView { dispatch_async(dispatch_get_main_queue(), ^{ [self.view addSubview:self.spinner]; [self.spinner startAnimating]; });}

- (void)webViewDidFinishLoad:(UIWebView *)webView {}

20

Page 21: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebViewUIActivityIndicatorView

// DetailViewController.m

- (void)configureView{ // ... self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner.center = self.view.center;

NSURL *theURL = [[NSURL alloc] initWithString:[self.detailItem valueForKey:@"url"]]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theURL];

[self.webView setDelegate:self]; [self.webView loadRequest:request];}

#pragma mark - UIWebViewDelegate

- (void)webViewDidStartLoad:(UIWebView *)webView { dispatch_async(dispatch_get_main_queue(), ^{ [self.view addSubview:self.spinner]; [self.spinner startAnimating]; });}

- (void)webViewDidFinishLoad:(UIWebView *)webView { dispatch_async(dispatch_get_main_queue(), ^{ });}

21

Page 22: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

UIWebViewUIActivityIndicatorView

// DetailViewController.m

- (void)configureView{ // ... self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner.center = self.view.center;

NSURL *theURL = [[NSURL alloc] initWithString:[self.detailItem valueForKey:@"url"]]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theURL];

[self.webView setDelegate:self]; [self.webView loadRequest:request];}

#pragma mark - UIWebViewDelegate

- (void)webViewDidStartLoad:(UIWebView *)webView { dispatch_async(dispatch_get_main_queue(), ^{ [self.view addSubview:self.spinner]; [self.spinner startAnimating]; });}

- (void)webViewDidFinishLoad:(UIWebView *)webView { dispatch_async(dispatch_get_main_queue(), ^{ [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; });}

22

Page 23: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

Coffee Break!

23

Page 24: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

MVCView Controller Lifecycle

viewDidLoad:

viewWillAppear:

viewDidAppear:

didReceiveMemoryWarning:

24

Page 25: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

MVCView Controller Lifecycle

viewDidLoad:

“This method is called after the view controller has loaded its view hierarchy into memory. You usually override this method to perform additional

initialization on views that were loaded from nib files”- (void)viewDidLoad{ [super viewDidLoad]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner.center = self.view.center;}

25

Page 26: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

MVCView Controller Lifecycle

viewWillAppear:

“This method is called before the receiver’s view is about to be added to a view hierarchy. You can override this method to perform custom tasks

associated with displaying the view”- (void)viewDidLoad{ [super viewDidLoad]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner.center = self.view.center;}

- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"];}

26

Page 27: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

MVCView Controller Lifecycle

viewDidAppear:

“You can override this method to perform additional tasks associated with presenting the view”

- (void)viewDidLoad{ [super viewDidLoad]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner.center = self.view.center;}

- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.titleLabel.text = [self.detailItem valueForKey:@"title"]; self.authorLabel.text = [self.detailItem valueForKey:@"author"];}

- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; NSURL *theURL = [[NSURL alloc] initWithString:[self.detailItem valueForKey:@"url"]]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theURL]; [self.webView setDelegate:self]; [self.webView loadRequest:request];}

27

Page 28: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

MVCView Controller Lifecycle

didReceiveMemoryWarning:

“You can override this method to release any additional memory used by your view

controller”

28

Page 29: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

EjercicioNew Video View Controller en iPad

29

Page 30: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

iOS SimulatorFile

Open Printer SimulatorSave Screen Shot ⌘S

30

Page 31: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

iOS SimulatorHardware

Device iPad 2, mini

iPad (Retina) iPhone 3G, 3GS

iPhone (Retina 3.5-inch) 4, 4S

iPhone (Retina 4-inch) 5, iPod Touch

Version 5.0 (9A334) WWDC 2011

5.1 (9B176) 6.0 (10A403) WWDC 2012

6.1 (10B141)

31

Page 32: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

iOS SimulatorHardware

Rotate Left ⌘←Rotate Right ⌘→Shake Gesture ^⌘Z

32

Page 33: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

iOS SimulatorHardware

Home ⇧⌘HLock ⌘L

33

Page 34: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

iOS SimulatorHardware

Simulate Memory Warning didReceiveMemoryWarning:

Toggle In-Call Status Bar ⌘TSimulate Hardware KeyboardTV Out Disabled 640 x 480 720 x 480 1024 x 768 1280 x 720 (720p) 1920 x 1024 (1080p)

34

Page 35: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

iOS SimulatorDebug

Toggle Slow Animations

35

Page 36: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

iOS SimulatorDebug

Color Blended Layers Reduce amount of red to improve performance

Color Copied ImagesColor Misaligned ImagesColor Offscreen-Rendered

36

Page 37: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

iOS SimulatorDebug

Location None Custom Location... Apple Stores Apple City Bicycle Ride City Run Freeway Drive

37

Page 38: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

iOS SimulatorWindow

Scale 100% ⌘1 75% ⌘2 50% ⌘3

38

Page 39: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

InstrumentsProfiling

⌘I

39

Page 40: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

InstrumentsAllocations

40

Page 41: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

InstrumentsAllocations

- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning];

self.webView = nil; self.spinner = nil; self.authorLabel = nil; self.titleLabel = nil; self.detailItem = nil;}

41

Page 42: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

InstrumentsLeaks

42

Page 43: Formacion en movilidad: Conceptos de desarrollo en iOS (III)

¡Gracias!

43