Skip to content

Commit

Permalink
Fix bug: error message only show for less than 1 second in V2EXTableV…
Browse files Browse the repository at this point in the history
…iewController
  • Loading branch information
imWildCat committed Mar 3, 2014
1 parent 765cdc9 commit b40124b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 100 deletions.
98 changes: 2 additions & 96 deletions Tests/MyTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,102 +13,8 @@ @interface MyTest : GHTestCase <V2EXRequestDataDelegate>

@implementation MyTest

- (void)test2MakePlist {
V2EXNormalModel *model = [[V2EXNormalModel alloc] initWithDelegate:self];
[model getIndex];

- (void)testHelloWorld {
NSLog(@"Hello World!");
}

- (void)test4NodeList {
V2EXNormalModel *model = [[V2EXNormalModel alloc] initWithDelegate:self];
[model getTopicsList:@"qna"];
}

- (void)requestDataSuccess:(id)dataObject {
// NSLog(@"%@",dataObject);
#pragma mark - make plist
// TFHpple *doc = [[TFHpple alloc]initWithHTMLData:dataObject];
// NSArray *elements = [doc searchWithXPathQuery:@"/html/body/div[2]/div/div[3]/div[11]/table//a"];
// NSMutableString *string = [NSMutableString new];
// for (TFHppleElement *element in elements) {
// [string appendString:@"<string>"];
// [string appendString:[[element objectForKey:@"href"] stringByReplacingOccurrencesOfString:@"/go/" withString:@""]];
// [string appendString:@"</string>\n"];
// }
// NSLog(string);

#pragma mark - for node list
TFHpple *doc = [[TFHpple alloc]initWithHTMLData:dataObject];
NSArray *elements = [doc searchWithXPathQuery:@"//body/div[2]/div/div/div[@class='cell']/table[1]"];

NSMutableArray *array = [[NSMutableArray alloc] init];
for (TFHppleElement *element in elements) {
TFHppleElement *avatarElement = [[element searchWithXPathQuery:@"//td[1]/a/img"] objectAtIndex:0];
TFHppleElement *titleElement = [[element searchWithXPathQuery:@"//td[3]/span[@class='item_title']/a"] objectAtIndex:0];
TFHppleElement *userNameElement = [[element searchWithXPathQuery:@"//td[3]/span[@class='small fade']/strong"] objectAtIndex:0];
NSArray *replyElements = [element searchWithXPathQuery:@"//td[4]/a"];

NSString *replyCount;
if ([replyElements count] > 0)
{
TFHppleElement *replyElement = [replyElements objectAtIndex:0];
replyCount = [replyElement text];
} else {
replyCount = @"0";
}
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
[avatarElement objectForKey:@"src"], @"avatar",
[titleElement text], @"title",
[userNameElement text], @"username",
replyCount, @"replies", nil
];
[array addObject:dict];
}

NSLog(@"%@", array);


}

- (void)requestDataFailure:(NSString *)errorMessage {
NSLog(@"%@",errorMessage);
}





- (void)testString {
NSString *staString = [NSString stringWithUTF8String:"link = \"/t/100977#reply25\";"];
NSString *parten = @"/t/\d{0,16}#reply";
NSString *urlString= [NSString stringWithUTF8String:"link = \"/t/100977#reply25\";"];

NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"/t/[0-9]+#reply"
options:0
error:&error];
if (regex != nil) {
NSArray *array = [regex matchesInString: urlString
options: 0
range: NSMakeRange( 0, [urlString length])];
if ([array count] > 0) {
NSTextCheckingResult *match = [array objectAtIndex:0];
NSRange firstHalfRange = [match rangeAtIndex:0];
NSString *result = [[[urlString substringWithRange:firstHalfRange] stringByReplacingOccurrencesOfString:@"/t/" withString:@""] stringByReplacingOccurrencesOfString:@"#reply" withString:@""];
} else {

}
}

}

- (void)testNetWorking {
NSLog(@"%i", (NSUInteger)[[NSDate date] timeIntervalSince1970]);

}





@end
3 changes: 0 additions & 3 deletions V2EX/Controllers/V2EXTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ - (void)didReceiveMemoryWarning
#pragma mark - LoadData

- (void)requestDataSuccess:(NSDictionary *)dataObject {

[self.tableView reloadData];
[self hideProgressView];

Expand All @@ -79,8 +78,6 @@ - (void)requestDataSuccess:(NSDictionary *)dataObject {
}

- (void)requestDataFailure:(NSString *)errorMessage {
[self hideProgressView];

[self finishRefresh];
_loadingStatus = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion V2EX/V2EX-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>180</string>
<string>182</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
Expand Down

0 comments on commit b40124b

Please sign in to comment.