因爲cell是高效複用的,每當拖動後,在cell.contentView,這些個view就會重疊,網上找了些方法,結合本身的代碼,記錄下來。
code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //這裏的reuse,是cell的Identifier UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];; if (!cell) { //在 cell中增長鬚要的內容 cell add things } else { //移除原來的子視圖 while ([cell.contentView.subviews lastObject] != nil) { [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];} } //在 cell中增長鬚要的內容 cell add things return cell; }