kub*_*lay 13 iphone xcode objective-c uitableview uisearchdisplaycontroller
在我的tableview中有我从UITableViewCell类初始化的自定义单元格.我有第一个记录字母的部分,并有一个动态创建的indexPath.
我想在我的tableview中添加一个搜索显示控制器.所以我做了,创建了所有过滤数据的方法.我确信我的功能运行良好,因为我打印数组计数以筛选搜索结果.
我的问题是第一次加载视图时,数据在屏幕上.但当我点击搜索输入并输入一个字母时,我得到的'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
错误.在我使用断点后,我看到我的自定义单元格在搜索后为零.数据存在,但未初始化单元格.
这是我用于自定义单元初始化的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ObjectCell";
SpeakerCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *myObject = [[sections valueForKey:[[[sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.label1.text = [myObject objectForKey:@"myValue"];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我认为在将控件放入IB时我犯了一个错误.所以我添加了对象的截图:
我的表视图的连接检查器
我的搜索显示控制器的连接检查器
编辑:问题实际上已经解决,我使用了UISearchBar而不是搜索显示控制器,但我想这个问题仍然没有解决.所以我愿意尝试任何方法让它发挥作用.
nik*_*avi 54
截至此处搜索显示控制器问题,您需要访问self.tableView
而不是tableView
:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CellId"];
// do your thing
return cell;
}
Run Code Online (Sandbox Code Playgroud)