Repository navigation
Expand file tree
/
Copy pathMainViewController.m
More file actions
87 lines (79 loc) · 2.65 KB
/
Copy pathMainViewController.m
File metadata and controls
87 lines (79 loc) · 2.65 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
80
81
82
83
84
85
86
87
//
// MainViewController.m
// ProgressView
//
// Created by Ansel on 12-10-28.
// Copyright (c) 2012年 Ansel. All rights reserved.
//
#import "MainViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setTitle:@"ProgressView"];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:@selector(back)];
[self.progress setUserInteractionEnabled:YES];
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Mail" style:UIBarButtonItemStyleBordered target:self action:@selector(Action:)]];
[self.progress setUserInteractionEnabled:YES];
[self.progress setBackgroundColor:[UIColor grayColor]];
[self.progress setTrackTintColor:[UIColor grayColor]];
[self.progress setProgress:0.0f];
self.progress.progressTintColor = [UIColor redColor];
self.progress.progressImage = [UIImage imageNamed:@"progressBackground.png"];
//block 代码示例
void (^printBlock)(NSString *x);
printBlock = ^(NSString* str)
{
NSLog(@"print:%@", str);
};
printBlock(@"hello world!");
//Thread
// [NSThread detachNewThreadSelector:@selector(ThreadOne) toTarget:self withObject:nil ];
// [NSThread detachNewThreadSelector:@selector(ThreadTwo) toTarget:self withObject:nil ];
//NotificationgCenter
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Action:) name:@"Center" object:nil];
// Do any additional setup after loading the view from its nib.
}
-(void)Action:(id)sender
{
EmailViewController *email = [[EmailViewController alloc]init];
[self.navigationController pushViewController:email animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)ThreadOne{
while (YES) {
NSLog(@"I am Here~");
sleep(1);
if(self.progress.progress == 1.0f)
{
self.progress.progress = 0.0f;
}
else
{
//[[NSNotificationCenter defaultCenter] postNotificationName:@"Center" object:self];
self.progress.progress +=0.01f;
}
}
}
-(void)ThreadTwo{
NSLog(@"I am Two");
}
- (IBAction)doSomething:(id)sender {
NSLog(@"doSomething");
[self.progress setProgress:0.7];
}
@end