我有一个 tableView,我想在 tableView 上应用搜索工具。为此,我需要 textField 和 search Button 但我不知道如何以编程方式创建这些。所以请告诉我如何创建这两个工具。
谢谢。
我有一个 tableView,我想在 tableView 上应用搜索工具。为此,我需要 textField 和 search Button 但我不知道如何以编程方式创建这些。所以请告诉我如何创建这两个工具。
谢谢。
尝试使用以下描述异步滚动条示例的链接
不过也可以参考上 一篇 UISearchBar 示例代码
有关在您键入时实现和获取结果的更多方法,请转到 apples 文档并参考UISearchBarDelegate 协议方法
这是UITextField和UIButton的文档。您可能还会发现UISearchBar很有用,它包含一个文本字段和一个按钮。
将您的视图添加到表视图的标题视图中。
你有一个表委托tableview:cellForRowAtIndexPath
。在此委托中添加以下代码。
//Suppose you want to add textfield and button at the first row
if(indexPath.Row == 0)
{
UITextField *txtSearch = [UITextField alloc] initWithFrame:CGRectMake(0,0,150,35)];
UIButton *btnSearch = [UIButton buttonWithType:UIButtoTypeCustom];
btnSearch.frame = CGRectMake(160,0,50,35);
[[cell contentView] addSubView:txtSearch];
[[cell contentView] addSubView:btnSearch];
}
您也可以为按钮添加事件,例如
[btnSearch addTarget:self action:@selector(eventName) forControlEvents:UIControlEventTouchUpInside];
谢谢