我相信我錯誤地實現了cellForRowAtIndexPath
。我有一個默認隱藏的UISlider
,並在表格單元格中按下按鈕時出現。當我按下第一個單元格中的按鈕時,滑塊不僅出現在第一個單元格中,而且在向下滾動時出現在每第三個單元格中。我目前通過將滑塊的隱藏屬性重置爲YES
cellForRowAtIndexPath
來避免這種情況。我也爲默認情況下需要隱藏的單元格中的其他視圖執行此操作。當我向後滾動到第一個單元格時,會產生一個新問題,因爲該屬性在cellForRowAtIndexPath
中重置,所以滑塊被隱藏。這讓我相信我做錯了什麼。重用表格單元問題
這裏是我的代碼:
- (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;
}
我現在明白了,但我在實施時遇到了問題。我不認爲我可以使用'NSDictionary *字典'B/C它在cellFor中重新創建...你能給更多的細節嗎? – mnort9
我的意思是當前保存在你的prseTrackArray中的字典 - 如果這是可變的,你可以在每行中按下按鈕時在其中設置一個新的鍵/值對。你有多少行,你的表視圖是否有段,並且可以同時顯示多個滑塊? – jrturton
行數是動態的。現在大約有100行(parseTrackArray.count),但隨着對象每天添加到parseTrackArray中,會隨着時間的推移而增加到成千上萬。 tableView沒有部分,一次會顯示多個滑塊。 – mnort9