TableView表示搜索的详细信息

时间:2013-11-05 19:45:52

标签: ios6 uitableview xcode5

我是Xcode iOS开发的新手。

我正在使用“自动完成”实现搜索。(对于每个用户插入的字母异步发送请求到服务器,通过此连接,我从服务器获取请求的数据)。 这部分工作得非常好:))

我的问题是在表格视图中表示搜索结果,我google了很多 但我找不到任何可以帮助我的好榜样。 当tableView第一次绘制时,一切都很好,但是当我获取另一个请求时: (一旦按下第二个键,请求将返回新数据,我想在表中绘制它,而不包含先前的数据)。

我的应用程序崩溃,异常“发送到实例0x的错误选择器......”

我将获取的数据存储在NSArray * FetchedData中; 之后我改变了:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:    (NSInteger)section
{
     return [FetchedData count];
}

在其他功能中(我想我必须在这里改变一些东西,但我不知道是什么)。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
{


cell.cellName.text = (NSString*)[FetchedData objectAtIndex:indexPath.row];
return cell;
}

获取FetchedData后,我调用了函数:       [self.tableView reloadData];

但在上面的函数中,我试图表示下一个提取的数据后崩溃了 这与前一个不同(它甚至可以是空的)

我想我可能需要删除所有以前的单元格, 但我不知道该怎么做。(我尝试了谷歌和本网站的一些代码,但我缺乏基本知识,我不断得到所有可能的例外)。

请有人能给我一个很好的例子并给出基本的解释吗?我非常感谢

感谢。

1 个答案:

答案 0 :(得分:0)

您需要在某处注册tableViewCell类(viewDidLoad),

[self.tableView registerClass:[CustomTableViewCellClass class] forCellReuseIdentifier:@"CellResuseIdentifier"];

然后进入,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath   *)indexPath
{
CustomTableViewCellClass *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CellReuseIdentifier"];

cell.cellName.text = (NSString*)[FetchedData objectAtIndex:indexPath.row];
return cell;
}

提取数据后,请致电

[self.tableView reloadData];