Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit c0c61b9

Browse files
author
张国晔
committed
Fix Crash
1 parent 073a0aa commit c0c61b9

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

Entry.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#import "Entry.h"
22

33
@implementation Entry
4+
45
- (id)initWithIndex:(NSInteger)index data:(NSNumber *)data {
56
self.index = index;
67
self.data = data;
78
return self;
89
}
10+
911
@end

Tweak.m

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@ - (NSInteger)tableView:(id)view numberOfRowsInSection:(NSInteger)section {
1919
for (NSInteger i = 0; i < num; i++) {
2020
NSString *sizeString = [[(UITableViewCell *)[self tableView:view cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:section]] detailTextLabel] text];
2121
float size = [sizeString floatValue];
22-
switch ([sizeString characterAtIndex:[sizeString length] - 2]) {
23-
case 'K':
24-
size *= 1024;
25-
break;
26-
case 'M':
27-
size *= 1024 * 1024;
28-
break;
29-
case 'G':
30-
size *= 1024 * 1024 * 1024;
31-
break;
32-
case 'T':
33-
size *= 1024 * 1024 * 1024 * 1024;
34-
}
22+
NSInteger length = [sizeString length];
23+
if (length > 2)
24+
switch ([sizeString characterAtIndex:length - 2]) {
25+
case 'M':
26+
size *= 1024;
27+
break;
28+
case 'G':
29+
size *= 1024 * 1024;
30+
break;
31+
case 'T':
32+
size *= 1024 * 1024 * 1024;
33+
}
3534
[data addObject:[[Entry alloc] initWithIndex:i data:@(size)]];
3635
}
3736
map = [data sortedArrayUsingComparator:^NSComparisonResult(Entry *a, Entry *b) {

0 commit comments

Comments
 (0)