【发布时间】:2014-06-01 11:52:05
【问题描述】:
我发现没有其他问题可以帮助我解决我的问题,但我担心这可能是由于我自己的无能。
我创建了一个表...该表显示了用户的音轨选项列表。我的应用程序背后的想法是用户从列表中选择他们想要的曲目,然后收到复选标记。然后,用户按下“播放”按钮,这些曲目会流式传输/分层,并以“音景”的形式播放。
我目前有两个问题。
一号:
当表格中的第一个选项被选中时...
列表中的第 9 个选项也是如此...
选择第二个选项时......
第 10 个选项也被选中等等...
这并不理想,因为它选择了用户不想要的选项。我看过类似的帖子,但我尝试根据这些帖子来解决这个问题并没有奏效。
问题编号 2:
事实证明,从这里实现音频非常困难......我一直在尝试使用 AVplayer?我仍然不知道这是否是正确的选择...对此的任何帮助也将不胜感激。
我有表格中的文本、缩略图名称和曲目名称的 .plist,.mp3 文件和缩略图已正确放置在我的项目中。音频但是我无法开始工作。
这是我的 .m 文件的代码。
#import "ASMRTableViewController.h"
@interface ASMRTableViewController ()
@end
@implementation ASMRTableViewController
{
NSArray *names;
NSArray *thumbnails;
NSArray *tracks;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Find out the path of the property list
NSString *path = [[NSBundle mainBundle] pathForResource:@"ExternalData" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
names = [dict objectForKey:@"Name"];
thumbnails = [dict objectForKey:@"Thumbnail"];
tracks = [dict objectForKey:@"Track"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [names count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ASMRTableIdentifier = @"ASMRTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ASMRTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ASMRTableIdentifier];
}
cell.textLabel.text = [names objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Checkmark
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//Selecting an option
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
//Initialise Alert
UIAlertView *messageAlert = [[UIAlertView alloc]
initWithTitle:@"Option Selected"
message:[names objectAtIndex:indexPath.row]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
// Display Alert Message
[messageAlert show];
//Add Tick
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
//Deselecting an option
else
{
//Initialise Alert
UIAlertView *messageAlert = [[UIAlertView alloc]
initWithTitle:@"Option Deselected"
message:[names objectAtIndex:indexPath.row]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
// Display Alert Message
[messageAlert show];
//Remove Tick
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
@end
我很乐意提供更多信息,不幸的是我的知识非常有限。
【问题讨论】:
-
我建议你把它分成两个问题。正如@delphidog 下面所说,您似乎需要注意单元格的重用。 AVPlayer 会同时播放曲目,但也许你需要从一开始就简化对它的使用(暂时忘记 plist 的东西并硬编码文件数据)
标签: ios uitableview audio avplayer