-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathViewController4.m
More file actions
68 lines (52 loc) · 1.67 KB
/
ViewController4.m
File metadata and controls
68 lines (52 loc) · 1.67 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
//
// ViewController4.m
// IOSPatterns
//
// Created by Sebastien on 11/28/12.
// Copyright (c) 2012 Sebastien. All rights reserved.
//
#import "ViewController4.h"
#import "BigCalculator4.h"
@interface ViewController4 ()
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;
@property (nonatomic, strong) BigCalculator4 *bigCalculator;
@end
@implementation ViewController4
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.bigCalculator = [[BigCalculator4 alloc] init];
[self.bigCalculator addCalculationProgressHandlerForTarget:self selector:@selector(calculationProgressChanged:)];
[self.bigCalculator addCalculationResultHandlerForTarget:self selector:@selector(calculationCompletedWithResult:)];
[self.bigCalculator startBigCalculationWithNumber:5.0 andNumber:7.0];
}
-(void) calculationProgressChanged:(float)progress
{
// update UI on main thread
dispatch_async(dispatch_get_main_queue(), ^{
self.progressView.progress = progress;
});
}
-(void) calculationCompletedWithResult:(float) result
{
// update UI on main thread
dispatch_async(dispatch_get_main_queue(), ^{
self.progressView.progress = 1.0f;
self.resultLabel.text = [NSString stringWithFormat:@"%f", result];
});
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end