From 37069be28978835d34e9691bcbd25f7c29566526 Mon Sep 17 00:00:00 2001 From: Lidia Chou Date: Thu, 19 Feb 2015 08:54:07 -0200 Subject: [PATCH 1/6] Adicionei linhas de comentario --- ContaPessoas/FirstViewController.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index fc70dd5..a0a36c6 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -2,8 +2,10 @@ // FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// Created by Lidia Chou on 2/18/15. +// Copyright (c) 2015 Lidia Chou. All rights reserved. +// +// // #import "FirstViewController.h" From 97625a36b7234a66d087cb2c2bba847b095448e7 Mon Sep 17 00:00:00 2001 From: Lidia Chou Date: Thu, 19 Feb 2015 11:42:33 -0200 Subject: [PATCH 2/6] agora aparece o total --- ContaPessoas/Contador.h | 4 ++++ ContaPessoas/Contador.m | 13 +++++++++++++ ContaPessoas/FirstViewController.h | 5 ++++- ContaPessoas/FirstViewController.m | 8 ++++---- ContaPessoas/SecondViewController.h | 5 ++++- ContaPessoas/SecondViewController.m | 10 +++++----- ContaPessoasTests/ContaPessoasTests.m | 1 + 7 files changed, 35 insertions(+), 11 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 18b7c16..f598978 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -8,11 +8,15 @@ @interface Contador : NSObject ++ (Contador *) contGlobal; + - (void)maisUmCueca; - (void)maisUmaGata; -(int)getBoys; -(int)getGirls; +-(int)getTotal; + @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..6f5082e 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -15,6 +15,15 @@ @implementation Contador { int girl; } ++ (Contador *)contGlobal{ + static Contador *contGlobal = nil; + + if (!contGlobal){ + contGlobal = [[Contador alloc] init]; + } + return contGlobal; +} + -(id)init { self = [super init]; if (self) { @@ -39,6 +48,10 @@ -(int)getGirls { return girl; } +-(int)getTotal{ + return boy + girl; +} + @end diff --git a/ContaPessoas/FirstViewController.h b/ContaPessoas/FirstViewController.h index 59c8301..cf4a501 100644 --- a/ContaPessoas/FirstViewController.h +++ b/ContaPessoas/FirstViewController.h @@ -7,8 +7,11 @@ // #import +@class Contador; -@interface FirstViewController : UIViewController +@interface FirstViewController : UIViewController{ + Contador *contador; +} - (IBAction)clickBoy:(id)sender; - (IBAction)clickGirl:(id)sender; diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index a0a36c6..a8d21eb 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -10,18 +10,18 @@ #import "FirstViewController.h" #import "Contador.h" +#import "SecondViewController.h" @interface FirstViewController () @end -@implementation FirstViewController { - Contador *contador; -} +@implementation FirstViewController + - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + contador = [Contador contGlobal]; // Do any additional setup after loading the view, typically from a nib. } diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index f907831..3278f39 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -7,8 +7,11 @@ // #import +@class Contador; -@interface SecondViewController : UIViewController +@interface SecondViewController : UIViewController{ + Contador *contador; +} @property (weak, nonatomic) IBOutlet UILabel *totalBoys; @property (weak, nonatomic) IBOutlet UILabel *totalGirls; diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index a2a66f5..2ed724b 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -8,10 +8,10 @@ #import "SecondViewController.h" #import "Contador.h" +#import "FirstViewController.h" + +@interface SecondViewController () -@interface SecondViewController () { - Contador *contador; -} @end @@ -19,7 +19,7 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + contador = [Contador contGlobal]; } @@ -32,7 +32,7 @@ - (void)didReceiveMemoryWarning { - (IBAction)click:(id)sender { _totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]]; _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; - _total.text = [NSString stringWithFormat:@"%d", [contador getGirls] + [contador getBoys] ]; + _total.text = [NSString stringWithFormat:@"%d", [contador getTotal] ]; } diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 579bb3f..8a36f2f 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -21,6 +21,7 @@ - (void)testContaMeninos { Contador *c = [[Contador alloc] init]; [c maisUmCueca]; XCTAssert(([c getBoys] == 1), @"Pass"); + XCTAssert(([c getGirls] == 0), @"Pass"); } - (void)testContaMeninas { From f91ec7634f2e907f5ae3f4d1e2d46a271f61c2a7 Mon Sep 17 00:00:00 2001 From: Lidia Chou Date: Fri, 20 Feb 2015 10:04:11 -0200 Subject: [PATCH 3/6] Delegate implementado --- ContaPessoas/Base.lproj/Main.storyboard | 9 --------- ContaPessoas/Contador.h | 2 ++ ContaPessoas/Contador.m | 3 +++ ContaPessoas/SecondViewController.h | 3 ++- ContaPessoas/SecondViewController.m | 4 +++- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ContaPessoas/Base.lproj/Main.storyboard b/ContaPessoas/Base.lproj/Main.storyboard index 99fa0dc..865e88a 100644 --- a/ContaPessoas/Base.lproj/Main.storyboard +++ b/ContaPessoas/Base.lproj/Main.storyboard @@ -123,15 +123,6 @@ - diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index f598978..8bfd599 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -18,5 +18,7 @@ -(int)getTotal; +@property (nonatomic, weak) id mostrar; + @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 6f5082e..f198b38 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -8,6 +8,7 @@ #import #import "Contador.h" +#import "SecondViewController.h" @implementation Contador { @@ -35,9 +36,11 @@ -(id)init { - (void)maisUmCueca { boy = boy + 1; + [_mostrar atualiza]; } - (void)maisUmaGata { girl++; + [_mostrar atualiza]; } -(int)getBoys { diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index 3278f39..d5d8aca 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -16,7 +16,8 @@ @property (weak, nonatomic) IBOutlet UILabel *totalBoys; @property (weak, nonatomic) IBOutlet UILabel *totalGirls; @property (weak, nonatomic) IBOutlet UILabel *total; -- (IBAction)click:(id)sender; + +-(void)atualiza; @end diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index 2ed724b..c4ef08e 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -20,6 +20,8 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; contador = [Contador contGlobal]; + contador.mostrar = self; + [self atualiza]; } @@ -29,7 +31,7 @@ - (void)didReceiveMemoryWarning { // Dispose of any resources that can be recreated. } -- (IBAction)click:(id)sender { +- (void)atualiza { _totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]]; _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; _total.text = [NSString stringWithFormat:@"%d", [contador getTotal] ]; From 9871d82bdfea8d1d511162d37cf58cd940d2c559 Mon Sep 17 00:00:00 2001 From: Lidia Chou Date: Fri, 20 Feb 2015 10:08:11 -0200 Subject: [PATCH 4/6] =?UTF-8?q?Tirei=20um=20import=20que=20n=C3=A3o=20fazi?= =?UTF-8?q?a=20sentido?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ContaPessoas/Contador.m | 1 - 1 file changed, 1 deletion(-) diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index f198b38..8d76806 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -8,7 +8,6 @@ #import #import "Contador.h" -#import "SecondViewController.h" @implementation Contador { From 9b73a653720567fcbc66df45e596db2b661d13af Mon Sep 17 00:00:00 2001 From: Lidia Chou Date: Fri, 20 Feb 2015 10:32:04 -0200 Subject: [PATCH 5/6] Recoloquei o import, ignore meu ultimo commit --- ContaPessoas/Contador.m | 1 + 1 file changed, 1 insertion(+) diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 8d76806..f198b38 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -8,6 +8,7 @@ #import #import "Contador.h" +#import "SecondViewController.h" @implementation Contador { From fb4e521d0a2a6a112a547cc23f8b73dd4c58dc19 Mon Sep 17 00:00:00 2001 From: Lidia Chou Date: Fri, 20 Feb 2015 11:32:09 -0200 Subject: [PATCH 6/6] View atualizado --- ContaPessoas/Base.lproj/Main.storyboard | 55 ++++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/ContaPessoas/Base.lproj/Main.storyboard b/ContaPessoas/Base.lproj/Main.storyboard index 865e88a..d28dee7 100644 --- a/ContaPessoas/Base.lproj/Main.storyboard +++ b/ContaPessoas/Base.lproj/Main.storyboard @@ -2,6 +2,7 @@ + @@ -13,21 +14,14 @@ - + - - - + - - - - - - - - - + + + + + + + + +