2011-09-27 53 views
1

我已經實現了此刷卡刪除,但作爲一個清除按鈕,將uitableviewcells textlabel重置爲空...當此方法執行時,它完美的工作..但是,當用戶觸摸在刷卡後,同一細胞清除沒有任何反應......那麼如果再次觸摸它,它完美的作品...這裏是我的代碼..刷卡刪除在我的UITable造成奇怪的錯誤

// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source 
     //[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

    //reset uitableviewcell textlabel with default input "empty" 
     vehicleSearchObjectString = @"empty"; 
     [self.tableView reloadData]; //reloads the tabels so you can see the value. 

    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
    } 
} 

回答

1

你需要從數據源中刪除的對象。我看到你有這條線註釋了你在給定索引路徑中刪除行的位置,但實際上你還需要從任何列表或結構中刪除表中顯示的開始的對象。

我不知道這是什麼原因導致您的問題,但過去我遇到過一堆問題,因爲我忘了正確刪除我的對象。

+0

好的謝謝你的建議,我現在就來看看它..它是一個NSString,我已經進入了uitableview單元格..然後我將它更改回默認狀態「空」。 ..我不知道如何刪除一個NSString .. –

+0

事情是我不想刪除該行..我只是想清除我的tableviewcell中的文本標籤 –

+0

哦,所以你可以做的是寫: '[[[self tableView] cellForRowAtIndexPath:indexPath] textLabel] setText:@「empty」]'你不需要重新加載表格。 – Mason