123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #import "FMHomeViewController.h"
- #import "FMMusicViewController.h"
- #import "ShouCangVC.h"
- #import "SearchViewController.h"
- #import "DBDaoHelper.h"
- @interface FMHomeViewController ()
- {
- NSArray * array;
- }
- @end
- @implementation FMHomeViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.navigation.title = @"分类";
- [self.navigationController setNavigationBarHidden:YES animated:NO];
- self.view.backgroundColor = [UIColor whiteColor];
- self.navigation.leftImage =nil;
- self.navigation.rightImage = nil;
-
- self.navigation.navigaionBackColor = [UIColor colorWithRed:192.0f/255.0f green:37.0f/255.0f blue:62.0f/255.0f alpha:1.0f];
- self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f,self.navigation.size.height+self.navigation.origin.y, self.view.size.width, 44.0f)];
- _searchBar.delegate =self;
- _searchBar.placeholder = @"搜索:音乐";
-
- _searchBar.showsCancelButton = YES;
- _searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
- _searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
- _searchBar.keyboardType = UIKeyboardTypeDefault;
-
-
- _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)];
- _tableView.delegate =self;
- _tableView.dataSource = self;
- [self.view addSubview:_tableView];
-
- array = [DBDaoHelper myType];
- [self.view addSubview:_searchBar];
-
- UIButton * _buttonFriend= [UIButton buttonWithType:UIButtonTypeCustom];
- [_buttonFriend setTitle:@"添加分类" forState:UIControlStateNormal];
- [_buttonFriend setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
-
- [_buttonFriend addTarget:self action:@selector(topViewClick) forControlEvents:UIControlEventTouchUpInside];
- _buttonFriend.titleLabel.font = [UIFont systemFontOfSize:15];
- _buttonFriend.frame = CGRectMake(230-30, 30, 75+30, 30);
-
- [self.navigation addSubview:_buttonFriend];
- }
- -(void)topViewClick{
- UIAlertView *customAlertView = [[UIAlertView alloc] initWithTitle:@"请输入您的分类名称" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
-
- [customAlertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
-
- UITextField *nameField = [customAlertView textFieldAtIndex:0];
- nameField.placeholder = @"添加分类";
- [customAlertView show];
-
- }
- -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
-
- if (buttonIndex == alertView.firstOtherButtonIndex) {
- UITextField *nameField = [alertView textFieldAtIndex:0];
-
- [DBDaoHelper insertMyTypeWith:nameField.text];
- array = [DBDaoHelper myType];
- [_tableView reloadData];
-
- }
-
-
-
- }
- - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
- {
- [_searchBar resignFirstResponder];
- }
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
-
- [_searchBar resignFirstResponder];
-
- SearchViewController * pushController = [[SearchViewController alloc] init];
- pushController.nameMusic = searchBar.text;
- [self.navigationController pushViewController:pushController animated:YES];
- }
- #pragma mark - Table view data source,下面都是列表的代理事件
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [array count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString * dentifier = @"cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dentifier];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:dentifier];
- }
- cell.textLabel.text = [array objectAtIndex:indexPath.row];
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 44;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- ShouCangVC * pushController = [[ShouCangVC alloc] init];
- pushController.typeMusic = indexPath.row+1;
- [self.navigationController pushViewController:pushController animated:YES];
- }
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
- editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- if(indexPath.row>=5)
-
- return UITableViewCellEditingStyleDelete;
-
- else
-
- return UITableViewCellEditingStyleNone;
-
- }
- - (void) tableView:(UITableView *)tableView
- commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
- forRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- if (editingStyle == UITableViewCellEditingStyleDelete)
-
- {
- NSArray *arrTypeId = [DBDaoHelper myTypeId];
- NSString *type = [arrTypeId objectAtIndex:indexPath.row];
-
- [DBDaoHelper DeleteMyTypeWith:type];
- array = [DBDaoHelper myType];
- [_tableView reloadData];
-
- }
-
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- }
- @end
|