更新UITableViewCell的自定義單元格我已經嘗試了多達解決方案,我發現來解決這一問題。 我最近的代碼是show blow:的UITableView不是從情節串連圖板
static NSString *simpleTableIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
[[cell viewWithTag:1000] removeFromSuperview];
[[cell viewWithTag:2000] removeFromSuperview];
// other code for setting view that works perfect then
if(some condition){
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:@"upgrey.png"] forState:UIControlStateNormal];
btn.frame=upButton.frame;
[btn addTarget:self action:@selector(upButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btn];
UIButton *btn2=[UIButton buttonWithType:UIButtonTypeCustom];
[btn2 setImage:[UIImage imageNamed:@"downgrey.png"] forState:UIControlStateNormal];
btn2.frame=downButton.frame;
[btn2 addTarget:self action:@selector(downButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btn2];
btn.tag=1000;
btn2.tag=2000;
}
return cell;
但這不起作用。如果我添加 [[cell viewWithTag:1000] removeFromSuperview]; [[cell viewWithTag:2000] removeFromSuperview];
在開始從所有小區刪除按鈕。如果我不使用這個。它用這兩個按鈕顯示所有單元格。 在此先感謝。
你想在哪裏顯示這些按鈕?你的結果正是我期望的結果。 – woz 2014-11-20 18:47:47
如果條件是tru,我想將這些按鈕顯示爲tableview單元格的一部分。但如果我添加[[cell viewWithTag:1000] removeFromSuperview]; [[cell viewWithTag:2000] removeFromSuperview];線。它不顯示錶視圖中的按鈕,如果我不添加這些行。當我向上或向下滾動時,它顯示大多數表格單元格中的按鈕 – 2014-11-20 19:49:33
右,使用'removeFromSuperview'刪除按鈕。 – woz 2014-11-20 19:58:33