我有一个tableview
,其中包含自定义tableview cells
,每个自定义UIView
位于中心。我的tableview
有一个array
,其中包含每个都带有AVAsset
字典的字典和其他一些数据。我UIView
中的tableView cell
是一个自定义类,用于绘制资源的波形。我可以显示波形,但每次向阵列添加新资源并转到tableview
时,前一行中的UIView
消失,只留下最新行中的新波形。无法弄清楚为什么会这样。
表格查看方法:
- (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方法:
//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];
}
}
答案 0 :(得分:0)
行数可能无法更新。你试过吗
[yourTableView reloadData];
将新数据添加到阵列后?