UISearchBar - 为 UISearchBar 设定不同的 UITableView 背景

3

当我在UISearchBar中搜索时,我的普通tableView已经被设置为

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

{   

CustomCell *cell=(CustomCell *)[FieldTableView dequeueReusableCellWithIdentifier:@"Cell"];

        //set cell background color cleare color
         cell.backgroundColor=[UIColor clearColor];

if (isSearching) {
    cell.AddPFFieldLable.text = [filteredContentList objectAtIndex:indexPath.row];    
} else {
    cell.AddPFFieldLable.text=[[fieldArray objectAtIndex:indexPath.row]valueForKey:@"FName"];
}

我的普通表格视图

但当我搜索任何东西时,它会显示如下:

如何将其背景颜色更改为clearColor

如何将其背景颜色更改为clearColor


当搜索显示表格中出现搜索字段时,我无法选择它们。 - Shahrukh
2个回答

1

好的,我已经得到了我的查询的答案。

[self.searchDisplayController.searchResultsTableView setBackgroundColor:[UIColor clearColor]];

我在viewDidLoad中唯一缺少的东西。


0

我在我的UISearchBar中使用了这段代码。根据您的需求使用。

-(void)addSearchController {
    // No search results controller to display the search results in the current view

    [[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:CODE_2_COLOR];

    self.searchDisplayController.searchBar.placeholder = @"Search your connection list";


    UITextField *txfSearchField = [self.searchDisplayController.searchBar valueForKey:@"_searchField"];
    txfSearchField.backgroundColor = CODE_6_COLOR;
    self.searchDisplayController.searchBar.barTintColor=CODE_6_COLOR;
    CGRect rect = self.searchDisplayController.searchBar.frame;
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, rect.size.height-2,rect.size.width, 2)];
    lineView.backgroundColor = CODE_6_COLOR;
    [self.searchDisplayController.searchBar addSubview:lineView];
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{
                                                                                                 NSFontAttributeName: [FontManager getRobotoMediumFontWithSize:14],
                                                                                                 }];

    self.tableView.tableHeaderView = self.searchDisplayController.searchBar;

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接