#import "FindMyPhoneTonesViewController.h"
#import "pelAppDelegate.h"
#import "PlistOOP.h"
#import "pelSmartWatchData.h"
@interface FindMyPhoneTonesViewController ()
@end
@implementation FindMyPhoneTonesViewController
static int current;
@synthesize names;
@synthesize keys;
@synthesize items;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Find My Phone Tones";
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] init];
barButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = barButtonItem;
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"sound2" ofType:@"plist"];
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
self.names = data;
NSArray *array = [[names allKeys] sortedArrayUsingSelector:
@selector(compare:)];
self.keys = array;
}
- (void)viewDidUnload {
self.names = nil;
self.keys = nil;
[super viewDidUnload];
}
//kfq-----
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [names count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSString *key = [keys objectAtIndex:row];
NSString*nameSection = [names objectForKey:key];
static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SectionsTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SectionsTableIdentifier];
}
cell.textLabel.text =nameSection;
cell.selectionStyle=UITableViewCellSelectionStyleDefault;
NSString *currString=[pelSmartWatchData loadDataByName:@"currentData"];
current = [currString intValue];
NSLog(@"instring:%d",current);
//默认选中上一次
if(current==indexPath.row)
{
cell.imageView.image=[UIImage imageNamed:@"YES2.png"];
cell.textLabel.textColor=[UIColor blueColor];
}
else
{
cell.accessoryType=UITableViewCellAccessoryNone;
}
//kfq---4-28
// current=indexPath.row;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// [tableView reloadData];
if(indexPath.row==current){
return;
}
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
if(newCell.accessoryType==UITableViewCellAccessoryNone) {
// newCell.accessoryType=UITableViewCellAccessoryCheckmark;
newCell.textLabel.textColor=[UIColor blueColor];
newCell.imageView.image= [UIImage imageNamed:@"YES2.png"];
}
NSIndexPath*oldIndexPath =[NSIndexPath indexPathForRow:current inSection:0];
UITableViewCell*oldCell = [tableView cellForRowAtIndexPath:oldIndexPath];
if(oldCell.imageView.image==[UIImage imageNamed:@"YES2.png"]) {
oldCell.imageView.image=[UIImage imageNamed:@""];
oldCell.accessoryType=UITableViewCellAccessoryNone;
oldCell.textLabel.textColor=[UIColor blackColor];
// newCell.imageView.image= [UIImage imageNamed:@"YES2.png"];
}
current=indexPath.row;
// [self.FindMyPhoneToneTableView reloadData];
[tableView reloadData];
//kfq--4-29
NSString *stringInt = [NSString stringWithFormat:@"%d",current];
//kfq--5-4
[pelSmartWatchData saveDataByName:@"currentData" data:stringInt];
//kfq---4-25 保存选中声音的key
NSUInteger row = [indexPath row];
NSString *key = [keys objectAtIndex:row];
[pelSmartWatchData saveDataByName:@"soundKey" data:key];
[pelAppDelegate playSound:[key intValue]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end