Permalink
Browse files

Some bugs fixed.

  • Loading branch information...
1 parent e663208 commit fce822cc5447e9e3529e25f1ffe47305804e7d60 @kishikawakatsumi committed Jul 5, 2009
Showing with 21 additions and 15 deletions.
  1. +2 −1 Classes/FeedParser.h
  2. +8 −8 Classes/FeedParser.m
  3. +1 −0 Classes/HotEntryViewController.h
  4. +10 −6 Classes/HotEntryViewController.m
View
@@ -14,8 +14,9 @@
id callBackObject;
SEL callBack;
+ SEL completeSelector;
}
-+ (void)parseWithRequest:(NSURLRequest *)request callBackObject:(id)target callBack:(SEL)selector;
++ (void)parseWithRequest:(NSURLRequest *)aRequest callBackObject:(id)target callBack:(SEL)selector completeSelector:(SEL)comleteSel;
@end
View
@@ -105,17 +105,16 @@ - (id)initWithRequest:(NSURLRequest*)aRequest {
return self;
}
-+ (void)parseWithRequest:(NSURLRequest *)aRequest callBackObject:(id)target callBack:(SEL)selector {
++ (void)parseWithRequest:(NSURLRequest *)aRequest callBackObject:(id)target callBack:(SEL)selector completeSelector:(SEL)comleteSel {
FeedParser *parser = [[FeedParser alloc] initWithRequest:aRequest];
parser->callBackObject = [target retain];
parser->callBack = selector;
+ parser->completeSelector = comleteSel;
[parser start];
}
- (void)dealloc {
[request release], request = nil;
- [conn cancel];
- [conn release], conn = nil;
[channel release], channel = nil;
[currentCharacters release], currentCharacters = nil;
[callBackObject release], callBackObject = nil;
@@ -124,7 +123,6 @@ - (void)dealloc {
}
- (void)start {
- [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
parserContext = xmlCreatePushParserCtxt(&_saxHandlerStruct, self, NULL, 0, NULL);
[NSURLConnection connectionWithRequest:request delegate:self];
}
@@ -141,16 +139,18 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if (parserContext) {
xmlFreeParserCtxt(parserContext), parserContext = NULL;
}
- conn = nil;
- [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
+
+ [callBackObject performSelectorOnMainThread:completeSelector withObject:nil waitUntilDone:NO];
+ [self release];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
if (parserContext) {
xmlFreeParserCtxt(parserContext), parserContext = NULL;
}
- conn = nil;
- [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
+
+ [callBackObject performSelectorOnMainThread:completeSelector withObject:nil waitUntilDone:NO];
+ [self release];
}
#pragma mark -- libxml handler --
@@ -5,6 +5,7 @@
NSMutableArray *hotEntries;
NSMutableArray *featuredEntries;
NSIndexPath *selectedRow;
+ NSUInteger finishCount;
}
@property (nonatomic, retain) UITableView *hotEntryView;
@@ -36,18 +36,26 @@ - (void)loadHotEntries {
LOG_CURRENT_METHOD;
NSString *URL = @"http://b.hatena.ne.jp/hotentry.rss";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];
- [FeedParser parseWithRequest:request callBackObject:self callBack:@selector(addHotEntry:)];
+ [FeedParser parseWithRequest:request callBackObject:self callBack:@selector(addHotEntry:) completeSelector:@selector(finishLoading)];
}
- (void)loadFeaturedEntries {
LOG_CURRENT_METHOD;
NSString *URL = @"http://b.hatena.ne.jp/entrylist?sort=hot&threshold=&mode=rss";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];
- [FeedParser parseWithRequest:request callBackObject:self callBack:@selector(addFeaturedEntry:)];
+ [FeedParser parseWithRequest:request callBackObject:self callBack:@selector(addFeaturedEntry:) completeSelector:@selector(finishLoading)];
+}
+
+- (void)finishLoading {
+ finishCount++;
+ if (finishCount == 2) {
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
+ }
}
- (void)loadEntries {
LOG(@"Hot Entries: refresh data.");
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[self loadHotEntries];
[self loadFeaturedEntries];
}
@@ -182,10 +190,6 @@ - (void)viewWillAppear:(BOOL)animated {
[self refleshIfNeeded];
}
-- (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
-}
-
- (void)didReceiveMemoryWarning {
LOG_CURRENT_METHOD;
[super didReceiveMemoryWarning];

0 comments on commit fce822c

Please sign in to comment.