I believe I am incorrectly implementing cellForRowAtIndexPath. I have a UISlider that is hidden by default and appears when a button is pressed in the table cell. When I press the button in the first cell,the slider appears not only in the first cell, but in every third cell when I scroll down. I am currently avoiding this by reseting the slider’s hidden property to YES in cellForRowAtIndexPath. I also do this for other views in the cell I need hidden by default. This creates a new issue when I scroll back up to the first cell, the slider is hidden because the property is reset in cellForRowAtIndexPath. This leads me to believe I’m doing something wrong.
Here is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
SongsCustomCell *songCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (songCell == nil) {
songCell = [[SongsCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSLog(@"new cell created");
}
NSDictionary *dictionary = [parseTrackArray objectAtIndex: indexPath.row];
NSString *trackTitle = [dictionary objectForKey:@"trackTitle"];
NSString *trackLink = [dictionary objectForKey:@"trackStreamLink"];
songCell.trackLinkString = trackLink;
songCell.trackTitleString = trackTitle;
[songCell.trackTitleLabel setFont:[UIFont fontWithName:@"Calibri" size:22]];
songCell.trackTitleLabel.text = [NSString stringWithFormat:@"%@", trackTitle];
songCell.playButton.hidden = NO;
songCell.playbackSlider.hidden = YES;
songCell.playerHasLoaded = NO;
songCell.moviePlayer.view.hidden = YES;
return songCell;
}
You need to store the hidden / unhidden status of your slider in your data model somewhere, and then set the slider’s visibility appropriately from that in cellForRowAtIndexPath. If only one slider is visible at once, you can store the index path as an ivar in your view controller, if not then you will need to have another key in your dictionary holding an NSNumber bool or something.