我发现没有其他问题可以帮助我解决我的问题,但我担心这可能是由于我自己的无能。
我已经创建了一个表...该表显示了用户的音轨选项列表。我的应用程序背后的想法是用户从列表中选择他们想要的轨道,然后收到复选标记。然后用户按下“播放”按钮,这些轨道被流式传输/分层在一起,并以“音景”的形式播放。
我目前有两个问题。
1号:
当将表中的第一个选项选中时...
列表中的第 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
我很乐意提供更多信息,不幸的是我的知识非常有限。
最佳答案
您可能会看到重复的复选标记,因为 tableview 正在重用单元格。重复使用的单元格中的数据不会为下一个使用它的单元格自动清除,因此您必须确保设置 全部 cellForRowAtIndexPath 中单元格的 UI 元素。在您的情况下,您所要做的就是创建一个数组来记住每个轨道的“已选中”/“未选中”状态,然后在 cellForRowAtIndexPath 中为单元格设置附件类型。
至于音频,请尝试使用 AVAudioPlayer。有很多非常好的基本教程可以指导您使用它。如果您仍然遇到问题,可以发布一些音频代码。
关于ios - TableView 的问题和音频 AVplayer 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23979547/