- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 TableView Controller ,它实现了 UISearchBarDelegate 和 UISearchDisplayDelegate。我有一个按钮可以为我的表格 View 切换编辑 View 。当处于编辑模式时,用户可以选择多行并复制它们、删除它们等。如果我尝试在搜索栏中输入内容,而 TableView 处于编辑模式,shouldReloadTableForSearchString 方法会触发,然后我会重新 -使用更新的谓词从核心数据中获取我的数据,并从函数返回 YES,表示应重新加载 TableView 。当显示过滤结果时,它们不处于编辑模式,即使在 cellForRowAtIndexPath 中我可以看到 tableView isEditing 是 YES。我看不到多选的圆圈。在选择多个项目之前,我需要能够让用户过滤他们的列表,以便显着限制结果。
为什么结果没有显示在编辑模式中?
编辑模式,不使用搜索栏:
在编辑模式下搜索会产生非编辑模式且未设置样式的结果:
提前致谢,亚历克斯
这里是 shouldReloadTableForSearchString 方法:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
NSPredicate *predicate = nil;
if ([searchString length])
{
NSArray* filteredTags = nil;
if ([searchString length] < 3)
{
// Check for tags starting with 1 or 2 characters.
filteredTags = [[tagResultsController fetchedObjects] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(TagEntity* te, NSDictionary *bindings)
{
if ([[[te.name lowercaseString] substringToIndex:[searchString length]] isEqualToString:[searchString lowercaseString]])
return YES;
return NO;
}]];
}
else
{
// Check for tags with 3 or more consecutive characters anywhere in name
filteredTags = [[tagResultsController fetchedObjects] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(TagEntity* te, NSDictionary *bindings)
{
if ([[te.name lowercaseString] rangeOfString:[searchString lowercaseString]].location != NSNotFound)
return YES;
return NO;
}]];
}
// OR ANY(self.tags) in %@
predicate = [NSPredicate predicateWithFormat:
@"ANY(self.songlists) in %@ AND (name contains[cd] %@ OR artist_name contains[cd] %@ OR number = %@ OR ANY(tag_entities) in %@)",
currentSonglist.songs, searchString, searchString, searchString,filteredTags];
[self.fetchedResultsController.fetchRequest setPredicate:predicate];
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
// Return YES to cause the search result table view to be reloaded.
}
return YES;
这是 .h 文件中我的核心数据 TableView 的标题:
@interface SonglistTVC : CoreDataTableViewController
<UISearchBarDelegate,
UISearchDisplayDelegate,
UIPickerViewDataSource,
UIPickerViewDelegate,
UIActionSheetDelegate,
AddSongTVCDelegate,
ListSelectorDelegate>
我知道它正在使用我的 TableView Controller ,因为 cellForRowAtIndexPath 和 didSelectRowAtIndexPath 都在触发。我可以在内部进行调试,并且在 TableView 上将 isEditing 设置为 YES。但是 TableView 并没有反射(reflect)出它正确的编辑模式样式。
这里是 cellForRowAtIndexPath,它在搜索框中输入字母后立即触发。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *identifier = @"SongCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:identifier];
Song* song = [self.fetchedResultsController objectAtIndexPath:indexPath];
UILabel* artistLabel = (UILabel*)[cell viewWithTag:ARTIST_NAME_TAG];
UILabel* songLabel = (UILabel*)[cell viewWithTag:SONG_NAME_TAG];
UILabel* keyLabel = (UILabel*)[cell viewWithTag:KEY_TAG];
UILabel* numberLabel = (UILabel*)[cell viewWithTag:NUMBER_TAG];
//artistLabel.font = [UIFont systemFontOfSize:17];
[artistLabel setText: song.artist_name];
[songLabel setText: song.name];
//[songLabel setFont:[UIFont systemFontOfSize:16]];
[keyLabel setText: song.key];
[numberLabel setText: [NSString stringWithFormat:@"%@", song.number]];
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,61)];
UIView *selectedBackView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,61)];
CAGradientLayer *backGradient = [[CAGradientLayer alloc] init];
backGradient.frame = cell.layer.bounds;
CAGradientLayer *selectedGradient = [[CAGradientLayer alloc] init];
selectedGradient.frame = cell.layer.bounds;
if (song.status == [NSNumber numberWithUnsignedInt: 1])
{
[backGradient setColors:[NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:240.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:1 green:1 blue:1 alpha:1.0f] CGColor],
nil]];
}
else if (song.status == [NSNumber numberWithUnsignedInt: 2])
{
[backGradient setColors:[NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:240.0f/255.0f green:240.0f/255.0f blue:200.0f/255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:1 green:1 blue:1 alpha:1.0f] CGColor],
nil]];
}
else if (song.status == [NSNumber numberWithUnsignedInt: 3])
{
[backGradient setColors:[NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:200.0f/255.0f green:240.0f/255.0f blue:200.0f/255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:1 green:1 blue:1 alpha:1.0f] CGColor],
nil]];
}
[selectedGradient setColors:[NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:255.0f/255.0f green:160.0f/255.0f blue:60.0f/255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:1 green:1 blue:1 alpha:0.7f] CGColor],
nil]];
if (![self.tableView isEditing] )
{
cell.backgroundView = backView;
[cell.backgroundView.layer insertSublayer:backGradient atIndex:1];
cell.selectedBackgroundView = selectedBackView;
[cell.selectedBackgroundView.layer insertSublayer:selectedGradient atIndex:1];
}
else
{
//cell.backgroundView = backView;
//[cell.backgroundView.layer insertSublayer:backGradient atIndex:1];
cell.selectedBackgroundView = backView;
[cell.selectedBackgroundView.layer insertSublayer:backGradient atIndex:1];
}
for (NSIndexPath* ip in selectedIndexes)
{
[self.tableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionNone];
}
[sortOrderPicker reloadAllComponents];
[self sendPickerDownAnimated:NO];
return cell;
我使用分段控件内的按钮来打开/关闭编辑:
- (IBAction)segmentChanged:(id)sender{
UISegmentedControl* sg = (UISegmentedControl*)sender;
if (sg.selectedSegmentIndex == 0)
{
// Edit
if (![self.tableView isEditing])
{
[self.tableView setEditing:YES animated:YES];
[self.navigationController setToolbarHidden:NO animated:YES];
}
else
{
[self.tableView setEditing:NO animated:YES];
[self.navigationController setToolbarHidden:YES animated:YES];
selectedIndexes = nil;
}
[self.tableView reloadData];
}
else
{
// Sort
if (pickerShown)
[self sendPickerDownAnimated:YES];
else
[self bringPickerUpAnimated:YES];
}
最佳答案
问题在于 UISearchDisplayController 会自动为您做很多事情。它创建自己的 TableView 来显示搜索结果,并管理该 TableView 。您可以将自己设置为该 TableView 的数据源和委托(delegate),默认情况下会自动为您完成,但这不是您的 TableView ,您无法控制它。如果你想要更好的方法是指定这是什么 TableView ,你需要设置搜索显示 Controller 的 searchResultsTableView
;或者您可以在事情进行时获得对它的引用(例如,通过 UISearchDisplayController 自己的委托(delegate)方法)。但即便如此,您也不会成为管理结果 TableView 的 UITableViewController;这完全是 UISearchDisplayController 内部的。如果您不喜欢那样,一个简单的解决方案是:不要使用 UISearchDisplayController - 考虑另一个界面。
关于objective-c - 在编辑模式下将 UISearchBar 与 UITableView 一起使用时,搜索结果不处于编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14151133/
我正在尝试在 IN sql 条件下使用数据库字段。我的字段是一串由逗号分隔的值(如 it,en,fr,de),我必须在 WHERE 子句中使用它,如下所示: WHERE d.iso639code =
他大家 我的以下代码有问题: import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp e
在处理 ReadOnlyMany 存储时,我正在努力理解 PersistentVolume 上的容量参数的概念,以及 PersistentVolumeClaim 上的存储请求。如果存储以只读方式安装
我试图让一个 while 循环在另一个 while 循环中工作,我之前已经让它工作过,但无法再次管理它。 我试图计算航类查询中的总记录,然后在小时记录中尝试添加时间。我已经让所有查询单独工作,但是当我
我们的数据库更新性能偶尔会大幅下降。 例如,表 FooTable 我们有大约 40 列与 varchar PK 此外还有 10 个索引。以下查询用时 44 秒,而在其他时候它几乎立即运行。在减速期间,
我可以在 Release模式下使用 Trace.WriteLine 吗? Trace.Write 和 Debug.Write 之间的主要区别是什么? 最佳答案 不同之处在于 Release模式。 当未
我刚刚遇到了一个非常奇怪的场景,并且在其他地方找不到任何相关信息。当 Xcode 在我的断点处中断时,整个系统的所有键盘输入都没有响应。我可以切换到另一个应用程序,但没有记录任何击键。 Xcode 本
我一直在尝试在一组 Raspberry Pi 上设置 K8s 集群。这是我的 GitHub 页面的链接,描述了整个设置: https://github.com/joesan/plant-infra/b
我的 pod 处于 Pending 状态,因为提到的所有答案我都试图获得描述输出但不知道为什么它保持在 Pending 状态: k8s@k8s-master:~/deployment$ kubectl
我已经开发了一个非消耗性的应用内购买iOS应用程序。我已经获取了应用内购买的 bundle 包标识符,并编写了代码并将其提交给appstore ...提交应用程序后,其状态显示在-App Purcha
我有 2 个具有一对多关系的实体,一个地址可以是多个员工。 MySQL 数据库: 地址 address_id INT PK AutoIncr 城市 VARCHAR 国家/地区 VARCHAR 员工 i
我想在我的项目中使用 ProGuard。我激活了选项 minifyEnabled。当我打开使用库 Retrofit2 的 Activity 时,应用程序崩溃并显示: 无法为接口(interface)
我刚刚在 MVC 应用程序中启用了 Application Insights,并注意到在本地调试时,我的 Azure Application Insight 中会捕获跟踪信息。 处于 Debug模式时
我正在使用一个启动和结束线程的类。线程是在构造函数中创建的。只要标志为 TRUE,线程函数就会继续循环。该标志是该类的静态成员。解构器将标志设置为 FALSE。这样,该类的每个实例都有一个关联的线程,
我有一个 Angular PWA。在我从 Angular 5.0 升级到 7.2 之前,它的 service worker 工作完美 升级后,我在/ngsw/state中看到以下错误 Driver s
可能有一些背景:当用户单击它时,我试图在可滚动的全屏 EditText 上方显示一个特定的键盘 View 。问题是如果光标位于 EditText 的底部,它会被弹出的键盘 View 隐藏。 与常规 I
当进度条处于 Activity 状态时禁用后台交互的正确方法是什么。 Box( modifier = Modifier.fillMaxSize(), contentAlignmen
这个问题在这里已经有了答案: Draw Rectangle inside picture box SizeMode Zoom (1 个回答) 关闭 3 年前。 我有一个 PictureBox1,其
我们刚刚开始在 kubernetes 上创建我们的集群。 现在我们尝试部署分蘖,但出现错误: NetworkPlugin cni failed to set up pod "tiller-deploy
我使用 NRPE 插件将一台 Linux 主机配置为 Nagios 监控服务器。 为此,我遵循以下 URL http://www.tecmint.com/how-to-add-linux-host-t
我是一名优秀的程序员,十分优秀!