简体   繁体   English

在另一个视图控制器中单击删除按钮后,如何在表格视图中删除单元格数据并重新排列

[英]how to delete a cell data in a table view and rearranging after clicking the delete button in another view controller

hii, 嗨,

i need delete a cell data in a table view and rearrange after clicking the delete button in another view controller i will go to another view controller on selecting index at row in atable view controller....please do need ful help 我需要在表格视图中删除单元格数据,然后在另一个视图控制器中单击删除按钮后重新排列。我将在选择可用视图控制器中的行索引时转到另一个视图控制器。...请确实提供帮助

Thanks&Regards Devi. 谢谢问候德维。

call 呼叫

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath  

this method with from another class... with editing style set to UITableViewCellEditingStyleDelete 另一个类中的此方法...,其编辑样式设置为UITableViewCellEditingStyleDelete

provided you have implement the same method in your previous class... 只要您在上一课中实现了相同的方法...

Pass a reference to your initial view controller with the table to the 2nd controller with you initialize and push it. 初始化并推送它时,将带有表的初始视图控制器的引用传递给第二个控制器。 Then you will be able to call any public methods on that view controller. 然后,您将能够在该视图控制器上调用任何公共方法。 This will allow you to define a method like -(void)deleteIt; 这将使您可以定义-(void)deleteIt;类的方法-(void)deleteIt; and call that directly from the other controller. 并直接从另一个控制器调用它。 Also, if you need to track which cell element was clicked, pass the index along also. 另外,如果您需要跟踪单击了哪个单元格元素,请同时传递索引。

EDIT 编辑

To pass data to the new view controller, you can do: 要将数据传递到新的视图控制器,您可以执行以下操作:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NextViewController *nvCon = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
    nvCon.rootViewCon = self;
    nvCon.selectedIndex = indexPath;
    [self.navigationController pushViewController:nvCon animated:YES];
    [nvCon release];
}

Then call a public method on rootViewCon to initiate the delete. 然后在rootViewCon上调用public方法以启动删除。 You can pretty much just copy the boilerplate code used for deleting table view cells here. 您几乎可以在这里复制用于删除表格视图单元格的样板代码。 There are many references on SO and in the Apple docs. 在SO和Apple文档中有很多参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM