我正在使用搜索欄和顯示控制器與我的視圖控制器。當我使用默認的UITableViewCell
時,一切正常。但是當我使用控制器的自定義單元格。它不會在拖動的標籤上顯示文字。如何在搜索欄中使用自定義單元格視圖類?
此代碼工作正確─
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.textLabel.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"userName"];
}
return cell;
}
現在我有分配有一個名爲SearchFriendCell
和標識SearchFriends
類的原型細胞。 SearchFriendCell
類包含帶插座的標籤。 現在,如果我用以下代碼替換上面的代碼,它不顯示任何結果。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SearchFriends";
SearchFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell = [[SearchFriendCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.friendName.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"userName"];// this line doesn't work
}
return cell;
}
在,如果我替換下面一行註釋行修改後的代碼,它顯示result-
cell.textLabel.text = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"userName"];
我不知道這裏有什麼問題。搜索欄顯示控制器無法識別我的原型單元。在此之前,我多次使用表視圖控制器,但是我沒有遇到這種類型的問題。 幫助我一些很好的答案。
沒有你連''中的friendName''IBOutlet' SearchFriendCell' – Akhilrajtr
什麼是FRIENDNAME是它是一個UILabel還是隻是NSString?它被添加到單元格內容視圖中嗎? – ahmedalkaff
它是一個真正的原型單元嗎? '[SearchFriendCell alloc] initWithStyle:...'是否被調用過? – Wain