在表格视图中仅对一行启用编辑模式 [英] Enabling edit mode for only one row in table view

查看:72
本文介绍了在表格视图中仅对一行启用编辑模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过调用[tableView setEditing:YES]来设置一会儿uitableview的编辑模式;但这将为表中的所有行设置编辑模式.

I can set the edit mode for a while uitableview by calling [tableView setEditing:YES]; But that sets the edit mode for all the rows in a table.

是否有一种方法可以检测到刷了哪一行,仅启用了该行的编辑模式?

Is there a way to detect what row was swiped an enable the edit mode only for that row?

谢谢

推荐答案

我没有对此进行编码,但这是个主意.

I haven't coded this up, but here's the idea.

在.h中创建selectionIndexPath

Create selectionIndexPath in .h

NSIndexPath *selectionIndexPath;

然后在.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

将indexPath保存到selectionIndexPath并调用:

save indexPath to selectionIndexPath and call:

[self.tableView setEditing:YES];

然后输入:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

if (selectionPath.row == indexPath.row)
    {
        return UITableViewCellEditingStyleDelete;
    }
    else
    {
        return UITableViewCellEditingStyleNone;     
    }
}

您还可以抓紧接触点,然后或多或少地做同样的事情.像这样...

You could also catch the touches and then do more or less the same thing. Something like this...

NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil)
{
        // save indexPath and setEditing Mode here
}

没有时间对其进行编码,但这是主要思想.

Didn't have any time to code it up, but that's the main idea.

这篇关于在表格视图中仅对一行启用编辑模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆