将表更改为编辑模式并删除普通 ViewController 中的行

编程入门 行业动态 更新时间:2024-10-28 06:25:51
本文介绍了将表更改为编辑模式并删除普通 ViewController 中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我只是将一个表插入到一个普通的 UIViewController 中,并将委托和源组件与文件的所有者连接起来.当我将数据插入表行时,一切正常.但现在我想知道如何删除行.

I just inserted a table into a normal UIViewController and connected the delegate and source components with the file's owner. Everything works fine when i insert data into the table rows. but now i am trying to find out how rows can be deleted.

我只是看了很多其他帖子,但找不到合适的解决方案.

I just looked at a lot of other posts, but couldn't find the right solution.

我试图为表格中的每一行插入一个辅助按钮:

I tried to insert a asseccory button for each row in the table:

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

我什至找到了按下附件按钮时将调用的方法:

i even found the method that will be called when the accessory button is pressed:

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{ NSLog(@"Accessory pressed"); //[self tableView:tableView willBeginEditingRowAtIndexPath:indexPath]; //[self tableView:nil canEditRowAtIndexPath:indexPath]; //[self setEditing:YES animated:YES]; }

在日志中打印了消息,但是我尝试调用的任何一种方法(已注释的方法)都没有将视图更改为编辑模式.我该如何解决这个问题?

Inside the log the message is printed, but no one of the methods that i tried to call (the commented one) did change the view to the edit mode. How can i solve this problem?

这是 UIViewController 的屏幕截图.我还没有集成导航控制器.

Here is a Screenshot of the UIViewController. I haven't integrated a navigationController.

推荐答案

我可以解决删除行的问题.为了使它工作,我像 ACB 告诉我的那样插入了以下方法:

I could just solve the problem for deleting the rows. To make it work i inserted like ACB told me, the following methods:

//when blue accessory button has been pressed - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{ //turn into edit mode [tableView setEditing:YES animated:YES]; } - (void)setEditing:(BOOL)editing animated:(BOOL)animated{ [super setEditing:editing animated:animated]; } // method to enable the deleting of rows -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { Activity *activity = [allActivities objectAtIndex:indexPath.row]; // remove the item from the array [allActivities removeObjectAtIndex:indexPath.row]; //delete element from database with created method [dataController deleteFromTable:@"activity" theElementWithID:activity._id]; [tableView setEditing:NO animated:YES]; // refresh the table view [tableView reloadData]; } }

我在 cocoapi.wordpress/tag/caneditrowatindexpath

但我仍然只有一个问题.如果有人进入编辑模式,并且不会删除一行,则不可能再次关闭编辑模式.如果您切换视图并再次返回,它会自动停止,否则不可能,因为我没有插入 NavigationController.

But i still have just one problem. If somebody enters in editing mode, and won't delete a row, there is no possibility, to turn the editing mode off again. If you switch the view and come back again it autmatically stops, but otherwise its not possible because i don't have a NavigationController inserted.

有没有办法在编辑时访问行左侧的删除控件的状态?检测是否有人再次关闭删除以跳出编辑模式会很有用.

Is there a way, to access the state of the Deletion Control on the left of the row while editing? it would be useful to detect if somebody turned the deletion off again to jump out of editing mode.

它可能不适合苹果用户指南,但我只是在我的第一个项目中,它应该可以正常工作.

It might not fit the apple user guide, but im just on my first project and it should just work.

更多推荐

将表更改为编辑模式并删除普通 ViewController 中的行

本文发布于:2023-10-26 01:27:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑   模式   将表更   ViewController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!