/SVN_Test/Vinh/VNExpressRSS/Classes/HomeViewController.m
http://doc-bao.googlecode.com/ · Objective C · 152 lines · 103 code · 32 blank · 17 comment · 2 complexity · 719ed35c6c4b41c5ca589a67e2f8d0af MD5 · raw file
- //
- // HomeViewController.m
- // VNExpressRSS
- //
- // Created by Vinh Huynh on 8/24/11.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import "HomeViewController.h"
- #import "HomeCell.h"
- #import "VNExpressRssController.h"
- @implementation HomeViewController
- @synthesize cell;
- @synthesize listNews;
- @synthesize detailController;
- @synthesize table;
- #pragma mark -
- #pragma mark View lifecycle
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.listNews = [[[NSMutableArray alloc] init] autorelease];
- NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Trang ch? - VNExpress",@"Name",@"http://vnexpress.net/rss/gl/trang-chu.rss",@"Link",nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Xă H?i - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/xa-hoi.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Th? Gi? - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/the-gioi.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Kinh Doanh - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/kinh-doanh.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"V?n Hóa - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/van-hoa.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Pháp Lu?t - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/phap-luat.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"??i S?ng - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/doi-song.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Th? Thao - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/the-thao.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"Khoa H?c - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/khoa-hoc.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Vi Tính - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/vi-tinh.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Ôtô Xe Máy - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/oto-xe-may.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"B?n ??c Vi?t - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/ban-doc-viet.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Tâm S? - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/ban-doc-viet-tam-su.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
-
- dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"C??i - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/cuoi.rss", @"Link", nil];
- [self.listNews addObject:dict];
- [dict release];
- }
- #pragma mark -
- #pragma mark Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- // Return the number of sections.
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- // Return the number of rows in the section.
- return [listNews count];
- }
- // Customize the appearance of table view cells.
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"Cell";
- cell = (HomeCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- [[NSBundle mainBundle] loadNibNamed:@"HomeCell" owner:self options:nil];
- }
- NSDictionary *dict = [self.listNews objectAtIndex:[indexPath row]];
- cell.titleLabel.text = [dict objectForKey:@"Name"];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 60;
- }
- #pragma mark -
- #pragma mark Table view delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- // Navigation logic may go here. Create and push another view controller.
- NSDictionary *dict = [self.listNews objectAtIndex:[indexPath row]];
- VNExpressRssController *rssController = [[VNExpressRssController alloc] init];
- // ...
- // Pass the selected object to the new view controller.
- [self.navigationController pushViewController:rssController animated:YES];
- [rssController loadNewsWithRssLink:[dict objectForKey:@"Link"]];
- [rssController initTextSelected:[dict objectForKey:@"Name"]];
- [rssController release];
- }
- #pragma mark -
- #pragma mark Memory management
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
-
- // Relinquish ownership any cached data, images, etc that aren't in use.
- }
- - (void)viewDidUnload {
- self.listNews = nil;
- // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
- // For example: self.myOutlet = nil;
- }
- - (void)dealloc {
- [super dealloc];
- self.table = nil;
- self.detailController = nil;
- self.cell = nil;
- self.listNews = nil;
- }
- @end