2012-03-07 26 views
3

我創建了一個tableview,可以在其中添加和刪除行。在每一行上都有一個標籤爲indexPath的按鈕。現在,當我在任何行上插入新行時,該單元格中的按鈕將獲得正確的標籤,但其他單元格按鈕會保留舊標籤。當插入新行時,UITableViewCell按鈕不會變爲標記

我試圖 1.重裝實現代碼如下 - 不工作 2.重裝部分 - 在所有indexPaths不工作 3.重裝行 - 不工作

我用FOLL代碼中插入新行,但該cellForRowAtInsexPath方法被調用一次,即只對新添加的行,由於這對老小區按鈕的標籤保持不變

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowNo inSection:0]; 
NSArray *otherArray = [NSArray arrayWithObject:indexPath]; 
[tableViewObj insertRowsAtIndexPaths:otherArray withRowAnimation:UITableViewRowAnimationNone]; 

和的cellForRowAtIndexPath:(NSIndexPath *)indexPath我有一個標籤設置爲a的按鈕infoButton每個索引路徑 infoButton.tag = indexPath.row;

+0

請張貼一些代碼,其他一切只是猜測。 – Alexander 2012-03-07 10:24:18

+0

請把你的代碼 – 2012-03-07 10:25:06

+3

爲什麼你的表格視圖單元格中的標籤是錯誤的方法來確定按下了哪個按鈕的另一個原因。在這裏看到我的答案:http://stackoverflow.com/a/9274863/852828 – jrturton 2012-03-07 10:42:50

回答

0

如果在創建單元格時使用「dequeueReusableCellWithIdentifier:」方法,那可能是按鈕標籤不改變的原因。

+0

是的,刪除後我得到了標籤正確。 – anshuman 2012-08-21 08:48:09

相關問題