问题与TableView和使用音频AVplayer



我发现没有其他问题可以帮助我解决我的问题,我担心这可能是由于我自己的无能。

我创建了一个表…此表为用户显示音轨选项列表。我的应用程序背后的想法是,用户从列表中选择他们想要的曲目,然后接收复选标记。然后用户按下"播放"按钮,这些音轨流/分层在一起,并作为一种"音景"的形式播放。

我现在有两个问题。

1号

:

当表中的第一个选项被选中时…
那么列表后面的第9个选项是……
当第二个选项被选中时…
第10个选项也被选中…

这是不理想的,因为它选择了用户不希望的选项。我看到过类似的帖子,但我试图根据这些来解决这个问题,但没有奏效。

第2期:

从这里实现音频被证明是非常困难的…我一直在尝试使用AVplayer?我仍然不知道这是否是正确的选择……如有任何帮助,我将不胜感激。

表中的文本有.plists,缩略图名称和曲目名称,.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。有很多非常好的基础教程可以指导你如何使用它。如果你仍然有问题,也许可以发布一些你的音频代码。

最新更新