【发布时间】:2011-08-08 09:10:22
【问题描述】:
今天我创建了一个 tableView,类似于 iPhone 联系人应用程序。我使用代码将 TableView 放入第一个单元格中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath indexAtPosition:0] == 0) {
static NSString *CellIdentifier = @"SearchCell";
UITableViewCell *searchBarCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
searchBar = [[UISearchBar alloc] initWithFrame:searchBarCell.frame];
[searchBarCell addSubview:searchBar];
return searchBarCell;
} // ...
searchBar 显示正确,但是当我实现搜索方法时,我发现在 searchBar 中键入时它们没有被输入...例如这个方法:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchTerm
我认为是因为 searchBar 是另一个类 tableView Cell 的子视图?这就是为什么搜索栏无法访问搜索方法的原因?我还将搜索栏委托设置为 self,仍然没有。
任何身体都可以帮忙吗? 提前非常感谢:)
【问题讨论】:
-
当你说你将delegate设置为self时,对象self是什么?
-
我不明白。我在 viewDidLoad 中做了这个; searchBar.delegate = self ...
-
你能把那部分代码贴在这里吗?
-
你是指搜索栏的方法吗?我做了 searchBar.delegate = self in view 确实加载了,我已经告诉过。
-
没有调用委托方法吗?
标签: iphone ios uitableview uisearchbar