2011-09-28 30 views
0

我重寫tableView:commitEditingStyle:forRowAtIndexPath成爲重置我的uitableviewcells中的文本標籤的方法,但是當用戶接下來觸及時會導致錯誤uitableview ..在它做任何事之前它必須被觸摸一次(所以需要兩次觸摸才能真正得到任何迴應)。桌面視圖刪除錯誤後,觸摸界面後的ViewView:commitEditingStyle:forRowAtIndexPath:已被使用

我希望有人可以幫助誰也曾經處於類似的情況;我的代碼如下..我debuged下來的的tableView:commitEditingStyle:forRowAtIndexPath方法,如果我註釋掉實現代碼如下:titleForDeleteConfirmationButtonForRowAtIndexPath:方法同樣的事情仍然發生。所以我覺得我做錯了什麼通過覆蓋其他方法。

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return @"Clear"; 
} 

// 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:UITableViewRowAnimationNone]; 

     //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 
    } 
} 

UPDATE 這是我把我的UITableViewCell爲textLabel

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     [[NSBundle mainBundle] loadNibNamed:@"VehicleSearchCell" owner:self options:nil]; 
     cell = vehicleSearchCell; 
     self.vehicleSearchCell = nil; 
    } 
    // Configure the cell... 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    if(indexPath.section == 0) 
    { 
     if(indexPath.row == 0) 
     { 
      UILabel *label1; 
      label1 = (UILabel *)[cell viewWithTag:1]; 
      label1.text = @"Manufacture"; 

      UILabel *label2; 
      label2 = (UILabel *)[cell viewWithTag:2]; 
      label2.text = vehicleSearchObjectString; 
     } 
//... 
+0

什麼是錯誤/問題?崩潰?什麼? – Bourne

+0

一旦我按下按鈕,單元格的uitextlabel設置爲「空」,如果我嘗試按下該文本單元格(它應該帶我到子視圖)它dosnt響應第一次觸摸..它響應第二..它就像我的整個uitableview變得沒有反應。 –

+0

vehicleSearchObjectString:這是什麼?你在哪裏設置它觸摸(將被刪除)tableViewCell? – Bourne

回答

0

如果你在這個方法中,您啓用了放在桌子上的編輯,我建議檢查哪裏/時被禁用,因爲這可能導致點擊看起來像被忽略。

我會按照另一個鉛是避免reloadData方法,激發了相當多的東西,有時不是由開發商控制的。您已獲得indexPath,因此您可以通過以下方式將目標單元更新爲:

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath 

上的表視圖。

最後一件事我會調查是蘋果公司在更新表評論: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html#//apple_ref/doc/uid/TP40007451-CH10-SW1 它說,提交...方法必須調用方法:

deleteRowsAtIndexPaths:withRowAnimation: 

或插入類似,但它不會如果不是,會怎樣。

+0

好的,謝謝你的建議..我現在要去看看他們:)謝謝。顯然,如果我得到他們中的任何一個,我會給你賞金。 –

+0

我嘗試過針對我的細胞進行更新,但只要一個人被刷過,它仍然影響整個桌子......看着你的其他建議仍然.. –

0

所以,我的問題解決了!......我基本上刪除.hmxib對面的文件再次開始幾乎複製我的代碼的意見和它完美的作品......我不知道爲什麼會這樣,也許事情我沒有當我的第一個設置了..我不知道......

相關問題