/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

  1. //
  2. // HomeViewController.m
  3. // VNExpressRSS
  4. //
  5. // Created by Vinh Huynh on 8/24/11.
  6. // Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "HomeViewController.h"
  9. #import "HomeCell.h"
  10. #import "VNExpressRssController.h"
  11. @implementation HomeViewController
  12. @synthesize cell;
  13. @synthesize listNews;
  14. @synthesize detailController;
  15. @synthesize table;
  16. #pragma mark -
  17. #pragma mark View lifecycle
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.listNews = [[[NSMutableArray alloc] init] autorelease];
  21. NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Trang ch? - VNExpress",@"Name",@"http://vnexpress.net/rss/gl/trang-chu.rss",@"Link",nil];
  22. [self.listNews addObject:dict];
  23. [dict release];
  24. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Xă H?i - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/xa-hoi.rss", @"Link", nil];
  25. [self.listNews addObject:dict];
  26. [dict release];
  27. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Th? Gi? - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/the-gioi.rss", @"Link", nil];
  28. [self.listNews addObject:dict];
  29. [dict release];
  30. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Kinh Doanh - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/kinh-doanh.rss", @"Link", nil];
  31. [self.listNews addObject:dict];
  32. [dict release];
  33. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"V?n Hóa - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/van-hoa.rss", @"Link", nil];
  34. [self.listNews addObject:dict];
  35. [dict release];
  36. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Pháp Lu?t - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/phap-luat.rss", @"Link", nil];
  37. [self.listNews addObject:dict];
  38. [dict release];
  39. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"??i S?ng - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/doi-song.rss", @"Link", nil];
  40. [self.listNews addObject:dict];
  41. [dict release];
  42. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Th? Thao - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/the-thao.rss", @"Link", nil];
  43. [self.listNews addObject:dict];
  44. [dict release];
  45. dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"Khoa H?c - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/khoa-hoc.rss", @"Link", nil];
  46. [self.listNews addObject:dict];
  47. [dict release];
  48. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Vi Tính - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/vi-tinh.rss", @"Link", nil];
  49. [self.listNews addObject:dict];
  50. [dict release];
  51. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Ôtô Xe Máy - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/oto-xe-may.rss", @"Link", nil];
  52. [self.listNews addObject:dict];
  53. [dict release];
  54. dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"B?n ??c Vi?t - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/ban-doc-viet.rss", @"Link", nil];
  55. [self.listNews addObject:dict];
  56. [dict release];
  57. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Tâm S? - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/ban-doc-viet-tam-su.rss", @"Link", nil];
  58. [self.listNews addObject:dict];
  59. [dict release];
  60. dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"C??i - VNExpress", @"Name", @"http://vnexpress.net/rss/gl/cuoi.rss", @"Link", nil];
  61. [self.listNews addObject:dict];
  62. [dict release];
  63. }
  64. #pragma mark -
  65. #pragma mark Table view data source
  66. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  67. // Return the number of sections.
  68. return 1;
  69. }
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  71. // Return the number of rows in the section.
  72. return [listNews count];
  73. }
  74. // Customize the appearance of table view cells.
  75. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  76. static NSString *CellIdentifier = @"Cell";
  77. cell = (HomeCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  78. if (cell == nil) {
  79. [[NSBundle mainBundle] loadNibNamed:@"HomeCell" owner:self options:nil];
  80. }
  81. NSDictionary *dict = [self.listNews objectAtIndex:[indexPath row]];
  82. cell.titleLabel.text = [dict objectForKey:@"Name"];
  83. return cell;
  84. }
  85. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  86. return 60;
  87. }
  88. #pragma mark -
  89. #pragma mark Table view delegate
  90. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  91. // Navigation logic may go here. Create and push another view controller.
  92. NSDictionary *dict = [self.listNews objectAtIndex:[indexPath row]];
  93. VNExpressRssController *rssController = [[VNExpressRssController alloc] init];
  94. // ...
  95. // Pass the selected object to the new view controller.
  96. [self.navigationController pushViewController:rssController animated:YES];
  97. [rssController loadNewsWithRssLink:[dict objectForKey:@"Link"]];
  98. [rssController initTextSelected:[dict objectForKey:@"Name"]];
  99. [rssController release];
  100. }
  101. #pragma mark -
  102. #pragma mark Memory management
  103. - (void)didReceiveMemoryWarning {
  104. // Releases the view if it doesn't have a superview.
  105. [super didReceiveMemoryWarning];
  106. // Relinquish ownership any cached data, images, etc that aren't in use.
  107. }
  108. - (void)viewDidUnload {
  109. self.listNews = nil;
  110. // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
  111. // For example: self.myOutlet = nil;
  112. }
  113. - (void)dealloc {
  114. [super dealloc];
  115. self.table = nil;
  116. self.detailController = nil;
  117. self.cell = nil;
  118. self.listNews = nil;
  119. }
  120. @end