FMMainViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // FMMainViewController.m
  3. // FreeMusic
  4. //
  5. //
  6. #import "FMMainViewController.h"
  7. #import "FMMainTableViewCell.h"
  8. #import "FMSingerSongListViewController.h"
  9. #import "FMMusicViewController.h"
  10. @interface FMMainViewController ()
  11. {
  12. NSMutableArray * array;
  13. }
  14. @end
  15. @implementation FMMainViewController
  16. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  17. {
  18. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  19. if (self) {
  20. // Custom initialization
  21. }
  22. return self;
  23. }
  24. - (void)viewDidLoad
  25. {
  26. [super viewDidLoad];
  27. [self.navigationController setNavigationBarHidden:YES animated:NO];
  28. self.view.backgroundColor = [UIColor whiteColor];
  29. self.navigation.leftImage =nil;// [UIImage imageNamed:@"nav_backbtn.png"];
  30. self.navigation.rightImage = [UIImage imageNamed:@"nav_music.png"];
  31. self.navigation.title = @"心情音乐";
  32. self.navigation.navigaionBackColor = [UIColor colorWithRed:192.0f/255.0f green:37.0f/255.0f blue:62.0f/255.0f alpha:1.0f];
  33. array = [NSMutableArray new];
  34. FMSingerModel * model = [FMSingerModel new];
  35. array = [model itemTop100];
  36. self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f,self.navigation.size.height+self.navigation.origin.y, self.view.size.width, 44.0f)];
  37. _searchBar.delegate =self;
  38. _searchBar.placeholder = @"搜索:歌手";
  39. // _searchBar.tintColor = [UIColor lightGrayColor];
  40. _searchBar.showsCancelButton = YES;
  41. _searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
  42. _searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
  43. _searchBar.keyboardType = UIKeyboardTypeDefault;
  44. // Create the search display controller
  45. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, _searchBar.size.height+_searchBar.origin.y, self.view.size.width, self.view.size.height-self.navigation.size.height-self.searchBar.size.height-48.5f)];
  46. _tableView.delegate =self;
  47. _tableView.dataSource = self;
  48. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  49. [self.view addSubview:_tableView];
  50. // Do any additional setup after loading the view.
  51. [self.view addSubview:_searchBar];
  52. // Do any additional setup after loading the view.
  53. }
  54. -(void)rightButtonClickEvent
  55. {
  56. if (globle.isPlaying) {
  57. FMMusicViewController * pushController = [FMMusicViewController shareMusicViewController];
  58. [self.navigationController pushViewController:pushController animated:YES];
  59. }
  60. }
  61. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  62. {
  63. [_searchBar resignFirstResponder];
  64. _searchBar.text = @"";
  65. FMSingerModel * model = [FMSingerModel new];
  66. array = [model itemTop100];
  67. [_tableView reloadData];
  68. }
  69. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  70. {
  71. // 键盘输入回车时进行响应
  72. [_searchBar resignFirstResponder];
  73. if ([array count]!=0) {
  74. [array removeAllObjects];
  75. }
  76. [ProgressHUD show:nil];
  77. [self getSingerData];
  78. }
  79. -(void)getSingerData
  80. {
  81. FMSingerModel * model = [FMSingerModel new];
  82. array = [model itemWith:_searchBar.text];
  83. [_tableView reloadData];
  84. [ProgressHUD dismiss];
  85. NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  86. [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
  87. }
  88. #pragma mark - Table view data source
  89. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  90. {
  91. //#warning Potentially incomplete method implementation.
  92. // Return the number of sections.
  93. return 1;
  94. }
  95. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  96. {
  97. //#warning Incomplete method implementation.
  98. // Return the number of rows in the section.
  99. return [array count];
  100. }
  101. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  102. {
  103. NSString * dentifier = @"cell";
  104. FMMainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dentifier];
  105. if (cell == nil) {
  106. cell = [[FMMainTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:dentifier];
  107. }
  108. FMSingerModel * model = [array objectAtIndex:indexPath.row];
  109. cell.model = model;
  110. return cell;
  111. }
  112. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. return 70;
  115. }
  116. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  117. {
  118. FMSingerModel * model = [array objectAtIndex:indexPath.row];
  119. FMSingerSongListViewController * pushController = [[FMSingerSongListViewController alloc] init];
  120. pushController.singerModel = model;
  121. [self.navigationController pushViewController:pushController animated:YES];
  122. }
  123. - (void)didReceiveMemoryWarning
  124. {
  125. [super didReceiveMemoryWarning];
  126. // Dispose of any resources that can be recreated.
  127. }
  128. /*
  129. #pragma mark - Navigation
  130. // In a storyboard-based application, you will often want to do a little preparation before navigation
  131. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  132. {
  133. // Get the new view controller using [segue destinationViewController].
  134. // Pass the selected object to the new view controller.
  135. }
  136. */
  137. @end