【发布时间】:2014-05-28 21:00:44
【问题描述】:
我有一个 uisearchbar 可以成功进行搜索。问题是searchResultsTableView 没有显示结果,因为它使用的是常规UITableViewCell 而不是我的自定义单元格。我已经在故事板中设置了这个自定义单元并连接了插座以确保一切正常。
我的cellForRowAtIndexPath 方法如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"InviteCell";
InviteTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if ( cell == nil ) {
cell = [[InviteTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
MyUser *person = nil;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
person = [self.filteredContactArray objectAtIndex:[indexPath row]];
//This works and shows
cell.detailTextLabel.text = @"testing if using default cell";
}
else
{
person = [self.inviteContactsArray objectAtIndex:[indexPath row]];
}
//InviteTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
person = [self.inviteContactsArray objectAtIndex:indexPath.row];
//these do not work and do not show in the results view
cell.nameLabel.text = person.fullName;
cell.emailLabel.text = person.email;
return cell;
}
结果视图如下所示:
【问题讨论】:
-
这个问题与我已经在这里回答的问题stackoverflow.com/questions/23920473/… 有何不同?
标签: ios cocoa-touch uitableview uisearchbar