xcode 在没有“setEditing:”方法的情况下启用拖放 UITableViewCell
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9829289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enable drag and drop UITableViewCell without "setEditing:" method
提问by Endrju
I'm trying to enable drag and drop UITableViewCell to swap them. It's not a problem, but i want to do it without "setEditing:" method. I want to swap cells before user drag cell using something like longGestureAction and drop it in another place, but without disabling selectRow method, and without show side icons.
我正在尝试启用拖放 UITableViewCell 来交换它们。这不是问题,但我想在没有“setEditing:”方法的情况下做到这一点。我想在用户使用 longGestureAction 之类的东西拖动单元格之前交换单元格并将其放在另一个地方,但不禁用 selectRow 方法,也不显示侧边图标。
I don't want something like this:
我不想要这样的东西:
1img http://dl.dropbox.com/u/10739464/stackoverflow/bad.png
1img http://dl.dropbox.com/u/10739464/stackoverflow/bad.png
I want something like this /with possibility to drag and drop of course/:
我想要这样的东西/当然可以拖放/:
2img http://dl.dropbox.com/u/10739464/stackoverflow/good.png
2img http://dl.dropbox.com/u/10739464/stackoverflow/good.png
Oh, I need to enable drag and drop like in "Clear" to-do app.
哦,我需要像在“清除”待办事项应用程序中那样启用拖放。
回答by akashivskyy
You can easily acheive this efect using-setEditing:
. You just have to assign some properties of your UITableViewCells
:
您可以轻松地达致这效应使用-setEditing:
。你只需要分配你的一些属性UITableViewCells
:
- (UITableViewCell*)tableView:(UITableView)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = ...;
cell.shouldIndentWhileEditing = NO;
cell.showsReorderControl = NO;
return cell;
}
Just make sure you call -setEditing:
in -viewDidLoad
method:
只要确保你调用-setEditing:
的-viewDidLoad
方法:
- (void)viewDidLoad {
[tableView setEditing:YES animated:NO];
}
EDIT:I searched a little bit on the web and found this: JTGestureBasedTableViewDemo for iOS. It's ClearApp-based and it's very impressive. You can take a look how it's done and apply some solutions in you app :)
编辑:我在网上搜索了一下,发现这个:JTGestureBasedTableViewDemo for iOS。它基于 ClearApp,非常令人印象深刻。您可以看看它是如何完成的,并在您的应用程序中应用一些解决方案:)
EDIT #2:If you want to enable selection during editing, just set this property of tableView:
编辑#2:如果要在编辑期间启用选择,只需设置 tableView 的此属性:
tableView.allowsSelectionDuringEditing = YES;
回答by user3300864
You can try this : https://github.com/ice3-software/i3-dragndropand this stack over flow link : drag and drop from uitableviewcell to uiimage view in ios
你可以试试这个:https: //github.com/ice3-software/i3-dragndrop和这个堆栈 over flow 链接:从 uitableviewcell 拖放到 ios 中的 uiimage 视图
(For the above mentioned library you can use try using 1st example.)
(对于上面提到的库,您可以尝试使用第一个示例。)
I would have liked it more to post this as comment..but, I don't have enough reputation.
我更希望将此作为评论发布。但是,我没有足够的声誉。
Hope it helps someone.
希望它可以帮助某人。