tableViewCell中的UIView消失
我有一个tableview
组成的自定义tableview cells
与每个UIView
在中心。 我的tableview
有一个由AVAsset
和其他一些数据字典组成的array
。 我的tableView cell
内的UIView
是一个自定义的类,绘制资产的波形。 我可以得到波形显示,但每次我添加一个新的资产到数组并去到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单元格方法:
//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]; } }
行数可能不会更新。 你试过了吗
[yourTableView reloadData];
将新数据添加到数组后?