#import "SecondViewController.h"@interfaceSecondViewController ()<UITableViewDelegate,UITableViewDataSource>@property(retain)NSMutableArray * dataSource;
@end@implementationSecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.//获取文件的相对路径NSString*path=[[NSBundle mainBundle]pathForResource:@"musicList" ofType:@"plist"];
//读取plist文件的内容NSArray*arr=[NSArray arrayWithContentsOfFile:path];
_dataSource=[NSMutableArray arrayWithArray:arr];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dataSource.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
staticNSString*cellID=@"cell";
UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:cellID];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
cell.textLabel.text=_dataSource[indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
[[NSNotificationCenter defaultCenter]postNotificationName:@"music" object:_dataSource[indexPath.row]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/@end