-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathViewController3.m
More file actions
79 lines (60 loc) · 2.11 KB
/
ViewController3.m
File metadata and controls
79 lines (60 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// ViewController3.m
// IOSPatterns
//
// Created by Sebastien on 11/28/12.
// Copyright (c) 2012 Sebastien. All rights reserved.
//
#import "ViewController3.h"
#import "BigCalculator3.h"
#import "NotificationDictKeys.h"
@interface ViewController3 ()
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;
@property (nonatomic, strong) BigCalculator3 *bigCalculator;
@end
@implementation ViewController3
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// subscribe to notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(calculatorProgressChanged:) name:kBigCalculatorProgressChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(calculatorCompletedCalculation:) name:kBigCalculatorCalculationCompleteNotification object:nil];
self.bigCalculator = [[BigCalculator3 alloc] init];
[self.bigCalculator startBigCalculationWithNumber:7.0 andNumber:5.0];
}
-(void) calculatorProgressChanged:(NSNotification *)notification
{
float value = [notification.userInfo[kCalProgressKey] floatValue];
// update the UI on the Main thread!
dispatch_async(dispatch_get_main_queue(), ^{
self.progressView.progress = value;
});
}
-(void) calculatorCompletedCalculation:(NSNotification *)notification
{
NSString *str = [NSString stringWithFormat:@"%f", [notification.userInfo[kCalResultKey] floatValue]];
// update the UI on the Main thread!
dispatch_async(dispatch_get_main_queue(), ^{
self.progressView.progress = 1.0f;
self.resultLabel.text = str;
});
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end