繁体   English   中英

当显示搜索栏时(如在Apple的邮件应用程序中),如何在工具栏中放置tableView的“编辑”按钮?

[英]How to put a tableView's Edit button in the toolbar when a search bar is shown (as in Apple's mail app)?

我想将编辑按钮放在底部的工具栏中 “编辑”按钮通常在viewDidLoad使用self.navigationItem.rightBarButtonItem = self.editButtonItem进行实例化,并且通常位于导航栏中。

尝试将“编辑”按钮(= self.editButtonItem )放入工具栏(通过将其添加到工具栏项目)时,不会显示按钮。 但是,我使用Interface Builder添加的所有其他工具栏项都正确显示。

您如何建议将此按钮添加到工具栏?

将“编辑”按钮添加到工具栏的原因是,当启用UISearchBar搜索处于活动状态且搜索栏隐藏导航栏中的编辑按钮时,将启用表格的编辑模式。

我想获得与Apple的电子邮件应用程序相同的行为,当搜索处于活动状态时,工具栏中会显示“编辑”按钮。

我将不胜感激任何建议。

谢谢您的帮助!!

您可以通过以下方式将“编辑”按钮添加到工具栏:

self.editButton = 
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit 
                                             target:nil 
                                             action:nil] 
autorelease];

NSArray *toolbarItems = 
[NSArray arrayWithObjects:self.editButton,nil];

self.toolbar.items = toolbarItems; 

如果要隐藏/显示它,只需切换其hidden属性:

self.editButton.hidden = YES;

你可以通过创建一个样式为UIBarButtonSystemItemEdit的新UIBarButtonItem来手动UIBarButtonSystemItemEdit 然后只需将其添加到[tableView setEditing:YES animated:YES]; ,分配目标和操作并调用[tableView setEditing:YES animated:YES];

暂无
暂无

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

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