簡單的問題,我根本不知道如何解決這個問題,我知道有很多類似的問題,對不起!UITableView內容重置時滾動
相當簡單,我給我的UITableViewCell
添加UITextField
。用戶可以輸入它,然後滾動出來並返回到視圖中,內容將被重置回默認狀態。
這是關於重新使用舊電池與dequeueReusableCellWithIdentifier
對嗎?我只是不明白如何解決它!
這裏是我的代碼:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//Stop repeating cell contents
else for (UIView *view in cell.contentView.subviews) [view removeFromSuperview];
//Add cell subviews here...
}
希望能對你有所幫助,謝謝。
嗯,我曾想過這件事。只需將我的代碼添加到if語句中,現在我的表就是空的。爲什麼會這樣? –
解決了它,我使用了我在故事板中使用的單元格標識符。通過使用一個獨特的,它會按預期添加子視圖。謝謝。 –