tableViewCell 中的 UIView 消失了 [英] UIView in tableViewCell disappearing

查看:28
本文介绍了tableViewCell 中的 UIView 消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 tableview,它由自定义的 tableview 单元格 组成,每个单元格的中心有一个 UIView.我的 tableview 有一个 array,它由字典组成,每个字典都有一个 AVAsset 和一些其他数据.我的 tableView cell 中的 UIView 是一个自定义类,用于绘制资产的波形.我可以让波形显示,但是每次我向数组中添加一个新资产并转到tableview 时,前一行中的UIView 消失了,只留下最新行中的新波形.无法弄清楚为什么会发生这种情况.

I have a tableview that consists of custom tableview cells each with a UIView at the center. My tableview has an array that consists of dictionaries each with an AVAsset and some other data. The UIView within my tableView cell is a custom class that draws a waveform of the assets. I can get the waveform to display, but every time I add a new asset to the array and go to the tableview, the UIView in the previous row disappears, leaving only the new waveform in the latest row. Can't figure out why this is happening.

表格视图方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"audioTableCell" owner:self options:nil];
    OSAudioTableCell *cell = [nib objectAtIndex:0];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    //Dictionary with data
    NSDictionary * packageInArray = [self.audioTableArray objectAtIndex:indexPath.row];

    cell.userName.text = [packageInArray objectForKey:@"userName"];
    cell.profilePicture.image = [UIImage imageWithData:[packageInArray objectForKey:@"profileImageData"]];

    //UIView related
    [cell setProgress:0]; //This sets timer to 0
    [cell setAsset:[packageInArray objectForKey:@"asset"]];  //This sets the asset
    [cell.waveView setBackgroundColor:[UIColor clearColor]];

    //NON related to UIView
    CALayer *imageLayer = cell.profilePicture.layer;
    [imageLayer setCornerRadius:20];
    imageLayer.borderColor = (__bridge CGColorRef)([UIColor grayColor]);
    [imageLayer setMasksToBounds:YES];    

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //When row is selected, the color of the UIView changes, this requires progress and the asset to be set again
    NSDictionary * packageInArray = [self.audioTableArray objectAtIndex:indexPath.row];

    //UIView related
    [((OSAudioTableCell*)[audioTable cellForRowAtIndexPath:indexPath]) setProgress:0];
    [((OSAudioTableCell*)[audioTable cellForRowAtIndexPath:indexPath]) setAsset:[packageInArray objectForKey:@"asset"]];
    [((OSAudioTableCell*)[audioTable cellForRowAtIndexPath:indexPath]) rowSelected:[packageInArray objectForKey:@"audioData"]];

}

TableView Cell 方法:

TableView Cell methods:

//Custom method that is called when the row is selected and commands audio player to play
-(void) rowSelected: (NSData*) data
{

    [[OSTablePlayerController getInstance] playAudio:data];

    self.timer = [NSTimer scheduledTimerWithTimeInterval:.0001 target:self selector:@selector(updateProgress:) userInfo:nil repeats:YES];

}

//monitors the progress of the player and draws the different colored UIView
- (void)updateProgress:(NSTimer *)timer {


    NSTimeInterval playTime = [[OSTablePlayerController getInstance] currentTime];
    NSTimeInterval duration = [[OSTablePlayerController getInstance] duration];


    float progress = playTime/duration;    

    //Draws new UIView based on progress
    [self.waveView setProgress:progress];

    if(!([OSTablePlayerController getInstance].player.playing))
    {
        [self audioPlayerDidFinishPlaying:[OSTablePlayerController getInstance].player successfully:YES];
    }

}

推荐答案

行数可能未更新.你试了吗

The number of rows may not be updating. Did you try

[yourTableView reloadData];

将新数据添加到数组之后?

After you add new data to the array?

这篇关于tableViewCell 中的 UIView 消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆