28399

UIView in tableViewCell disappearing

Question:

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.

Table View methods:

- (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 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]; } }

Answer1:

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

[yourTableView reloadData];

After you add new data to the array?

Recommend

  • how to select Table View row selection with custom checkbox button?
  • UITableView delegates not getting called after NSURL delegates
  • Perform Segue after clicking on search result
  • Potential Memory Leak for ABRecordCopyValue
  • I am unable to save and retrieve image in iOS
  • looping through subviews or a view
  • Out of Bounds Exception on NSArray thats Empty
  • Disable autorotate for view in tabview controller
  • UITableView scroll to specific section using UIPIckerView?
  • tracksWithMediaType returns 0 tracks sometimes
  • Compare two arrays and put equal objects into a new array [duplicate]
  • UITableView not displaying parsed data
  • How to fetch data from pList in Label
  • How to disable items in a combobox in Ext JS?
  • Creating a file name by adding two NSStrings
  • Load audio in DOCUMENTS when UITableView “cell” is pressed
  • Adding custom gesture to iCarousel items
  • Date formatter for converting 14-sept-2011 in 14th Sept
  • TouchesEnded not working in iOS5, working fine in iOS4
  • Store and fetch documents in/from app documents folder
  • NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for em
  • Display Local HTML file from documents directory in a UIWebView on iPhone
  • -[__NSArrayM insertObject:atIndex:]: object cannot be nil
  • UITableView In Edit Mode - Pressing Delete Makes My App Crash
  • Why won't my UITableViewCell deselect and update its text?
  • OAuth2 flow for mobile app
  • Grails eager fetch doesn't retrieve all data
  • How to extract a number from a string [duplicate]
  • Google Calendar Api is not showing event list
  • How to get a list with description of all dba packages
  • How to remove a SwiftyJSON element?
  • Row Count Is Returning the incorrect number using RaptureXML
  • Spring security and special characters
  • Deleting and Updating values from a cusrsor adapter
  • Obtain ObjectIdHex value from mgo query
  • Modifying destination and filename of gulp-svg-sprite
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • Bitwise OR returns boolean when one of operands is nil