2011-09-28 27 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对面的文件再次开始几乎复制我的代码的意见和它完美的作品......我不知道为什么会这样,也许事情我没有当我的第一个设置了..我不知道......

相关问题