model.h
@property (nonatomic,strong)NSString *name,*songer,*time;
//获取本地资源
-(NSMutableArray *)huoqu;
.m
-(NSMutableArray *)huoqu{
//获取本地music.plist
NSString *file=[[NSBundle mainBundle]pathForResource:@"Song.plist" ofType:nil] ;
NSMutableArray *array=[NSMutableArray arrayWithContentsOfFile:file];
return array;
}
controller.m
AudioModel *audio=[AudioModel new];
//获取model里面的plist属性给数组
arr=[audio huoqu];
////
////根据key赋值
cell.Name.text=[NSString stringWithFormat:@"%@",[arr[indexPath.row]objectForKey:@"SongName"]];
cell.Singer.text=[NSString stringWithFormat:@"%@",[arr[indexPath.row]objectForKey:@"Singer"]];
跳转传值
在第二个页面.h
//初始化model
@property (nonatomic,strong)AudioModel *AM;
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
AUDIOViewController *au=[AUDIOViewController new];
au.AM=[[AudioModel alloc]init];
au.AM.name=[arr[indexPath.row]objectForKey:@"SongName"];
au.AM.songer=[arr[indexPath.row]objectForKey:@"Singer"];
[self.navigationController pushViewController:au animated:YES];
}
第二个页面.m获取内容
- (void)viewDidLoad {
[super viewDidLoad];
v=[[v1 alloc]initWithFrame:self.view.frame];
[self.view addSubview:v];
//获取标题文字
self.navigationItem.title=[NSString stringWithFormat:@"%@:%@",self.ml.gename,self.ml.gequ];
//获取本地资源
NSString *file=[[NSBundle mainBundle]pathForResource:self.ml.gename ofType:@"mp3"];
//创建播放器
self.player=[[AVAudioPlayer alloc]initWithData:[NSData dataWithContentsOfFile:file] error:nil];
//播放
[self.player play];
[v.btn addTarget:self action:@selector(dj:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)dj:(UIButton *)xz{
if(xz.selected==NO){
v.btn.selected=YES;
[self.player play];
}else{
v.btn.selected=NO;
[self.player pause];
}
}