/
SCBadgeTableViewCellDemoViewController.m
116 lines (85 loc) · 3.04 KB
/
SCBadgeTableViewCellDemoViewController.m
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// SCBadgeTableViewCellDemoViewController.m
// SSCatalog
//
// Created by Sam Soffes on 01/29/11.
// Copyright 2011 Sam Soffes, Inc. All rights reserved.
//
#import "SCBadgeTableViewCellDemoViewController.h"
@implementation SCBadgeTableViewCellDemoViewController
#pragma mark - Class Methods
+ (NSString *)title {
return @"Badge Table View Cell";
}
#pragma mark - NSObject
- (id)init {
return self = [super initWithStyle:UITableViewStyleGrouped];
}
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = [[self class] title];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView reloadData];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}
return YES;
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return (section == 0) ? 4 : 12;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"cell";
SSBadgeTableViewCell *cell = (SSBadgeTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[SSBadgeTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease];
}
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0: {
cell.textLabel.text = @"Default Badge View";
cell.badgeView.textLabel.text = @"0";
cell.badgeView.badgeColor = [SSBadgeView defaultBadgeColor];
break;
}
case 1: {
cell.textLabel.text = @"Unread Count";
cell.badgeView.textLabel.text = @"3";
cell.badgeView.badgeColor = [UIColor colorWithRed:0.969f green:0.082f blue:0.078f alpha:1.0f];
break;
}
case 2: {
cell.textLabel.text = @"Text Badge";
cell.badgeView.textLabel.text = @"New";
cell.badgeView.badgeColor = [UIColor colorWithRed:0.388f green:0.686f blue:0.239f alpha:1.0f];
break;
}
case 3: {
cell.textLabel.text = @"Nil value";
cell.badgeView.textLabel.text = nil;
cell.badgeView.badgeColor = [SSBadgeView defaultBadgeColor];
break;
}
}
} else {
NSNumber *number = [NSNumber numberWithInteger:indexPath.row * 256];
cell.textLabel.text = [[NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterSpellOutStyle] capitalizedString];
cell.badgeView.textLabel.text = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterDecimalStyle];
cell.badgeView.badgeColor = [SSBadgeView defaultBadgeColor];
}
return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end