- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的 TableView Controller ,顶部有一个搜索栏。用户开始输入,如果没有找到结果,我会显示一个我以编程方式创建的 UIButton。
奇怪的是,如果我使用 UIButton,我键入每个字母时,屏幕都会刷新,您可以看到按钮的文本再次闪烁。它非常明显且不平滑。因此,用户输入一个字母并显示“单击此处创建”等。但是我输入的每个字母,该文本似乎都会重新呈现。
但是,如果我对 UILabel 执行完全相同的操作,它不会对每个键入的字母重新呈现并且非常流畅。
我使用按钮的原因是,如果用户输入的名称不存在,单击此按钮将为用户创建名称。我假设我不能为 UILabel 调用选择器,我可以吗?
这是我在 UIButton 中使用的代码:
在
viewDidLoad:
self.createButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//self.createButton = [[UIButton alloc] init];
self.createButton.frame = CGRectMake(-15, 90, 300, 30);
[self.createButton addTarget:self action:@selector(createButtonWasTapped:) forControlEvents:UIControlEventTouchUpInside];
self.createButton.backgroundColor = [UIColor clearColor];
self.createButton.showsTouchWhenHighlighted = YES;
self.createButton.tintColor = [UIColor whiteColor];
self.createButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
//self.createButton.opaque = NO;
self.createButton.hidden = YES;
[self.view addSubview:self.createButton];
在下面的方法中,如果没有找到结果,我将动态创建按钮:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
self.nameAddSearchBar.showsCancelButton = YES;
_autocompleteFetchedResultsController = nil;
NSError *error;
if (![[self autocompleteFetchedResultsController] performFetch:&error])
{
// Handle Error
}
else
{
[self.nameAddSearchTableView reloadData];
[self.createButton setHidden:_autocompleteFetchedResultsController.fetchedObjects.count > 0];
[self.createButton setTitle:[NSString stringWithFormat:@"Click Here to Create %@", self.nameAddSearchBar.text] forState:UIControlStateNormal];
... more code
}
按钮的选择器正在调用:
- (void)createButtonWasTapped:(id)sender
{
self.selectedName = self.nameAddSearchBar.text;
[self.delegate nameTextFieldTableViewController:self didSelectCell:self.selectedName];
[self dismissViewControllerAnimated:YES completion:nil];
}
我找不到从 UILabel 调用选择器的方法,但如果可以,那将解决我的问题。如果我做不到,我需要理解为什么每次输入字母时,我的“按钮”都会重新呈现。
任何帮助都会很有帮助!谢谢,
最佳答案
这是一个非常简单的修复。
我将按钮类型从圆角矩形更改为自定义:
self.createButton = [UIButton buttonWithType:UIButtonTypeCustom];
..随着这个变化,闪烁停止了!奇怪,但对我来说完全没问题!
关于ios - 在 TableView Controller 中搜索时,与 UILabel 相比,动态创建的 UIButton 的屏幕闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22192080/
这个问题在这里已经有了答案: 11年前关闭。 Possible Duplicate: Haskell: difference between . (dot) and $ (dollar sign) 好
我对 Java 平台没有任何了解,我想知道可以使用哪些工具(和方法)来帮助开发用 Java 编写的可维护代码。 我知道可以使用: 适用于任何环境的敏捷方法 用于单元测试代码的 jUnit/jMock(
我们的产品需要支持 IE9,但我们一直假设 IE9 支持 IE10+ CSS 规则。 是否有一种巧妙的方法来获取在 IE10+ 中有效但在 IE9 中不受支持的所有 CSS 规则,目的是在静态代码分析
我需要为 MyString 类重载运算符 + 和 +=。 MyString.h class MyString { char* m_pStr; }; 主要
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在升级现有的旧代码以使用 VS 2019*,在代码中我有以下函数在返回行失败: int foo(const char *fn) const { ofstream out(fn,ios::b
我想使用 R2D3 pacakge 在 R 中,但我不确定这个包与 D3.js 库的关系。 R2D3 是否以任何方式限制 D3 的功能?我们可以将 R 中的所有 D3 功能和特性与 R2D3 一起使用
我正在使用 WPF 语音识别库,试图在桌面应用程序中使用它来替代菜单命令。 (我想专注于没有键盘的平板电脑体验)。它可以工作 - 有点,除了识别的准确性太差以至于无法使用。所以我试着听写到 Word。
我在学校参加数据库类(class)。老师给了我们一个简单的练习:考虑以下简单的模式: Table Book: Column title (primary key) Column gen
我正在尝试学习 MVVM 模式,特别是当 View 表示数据库表时该怎么做,但 View 有几个元素表示单个数据库字段。举个简单的例子: 假设我有一个 DateTime 类型的数据库字段(每个数据库字
我有两张 table 。表单有约 77000 行。日志约有 270 万行。 以下查询将在不到一秒的时间内返回“30198”: SELECT COUNT(DISTINCT logs.DOCID) FRO
当您在 Eviews 中进行回归时,您会得到一组这样的统计数据: 在 R 中有没有一种方法可以在一个列表中获得所有/大部分关于 R 回归的统计数据? 最佳答案 请参阅summary,它将为大多数回归对
如果我枚举 type XType int const ( X1 XType = iota X2 ... Xn ) var XTypeNames = []string{"x1", "x2
我正在试用 ranger R包加速做了很多randomForest计算。我正在检查我从中得到的预测,并注意到一些有趣的事情,因为所做的预测完全不正确。 以下是比较 randomForest 的可重现示
我发现 Clang 编译速度比 GCC 慢了四倍。知道是什么原因造成的吗? ebg@tsuki(250)$ time /usr/bin/cc -DHC4 -DSAFETY -DNOREDUCE -DN
我注意到在尝试以 JSON 格式发布表单数据时,以下内容不起作用: $.ajax({ type: "POST", url: url, data: JSON.string
我的代码库中有很多 #if DEBUG/#endif 语句,它们大多具有断言类型逻辑,我不敢在生产环境中运行这些逻辑。 [Conditional("DEBUG")] public void Check
所以我正在开发一个平方根计算器,但我不知道 while 循环是否比 do while 循环更适合。 double x, y = 1.0, newY, squareRoot; bool
我有两个列表,一个是所有语言,另一个是网站拥有的语言子集,我的想法是返回所有语言,但如果子集的元素对应于所有语言的列表,则更改 bool 值的属性. 语言的DTO: public class DTOL
以下控制台应用程序运行正常 - 我很惊讶它没有出错。 class DelegateExperiments { //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
我是一名优秀的程序员,十分优秀!