Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 有没有办法自定义UISearchDisplayController单元格_Objective C_Ios - Fatal编程技术网

Objective c 有没有办法自定义UISearchDisplayController单元格

Objective c 有没有办法自定义UISearchDisplayController单元格,objective-c,ios,Objective C,Ios,我正在使用UISearchDisplayController进行搜索,如果可能的话,我希望向每个单元格添加更多元素。进行了一些搜索,但找不到任何信息。唯一的方法是使用tableview复制它。除了textlabel.text,我还可以设置其他属性吗 提前谢谢 是,您可以设置cell.imageView、cell.accessoryView、cell.BackGroundView。。等等 阅读本文档了解更多信息是,您可以设置cell.imageView、cell.accessoryView、cel

我正在使用UISearchDisplayController进行搜索,如果可能的话,我希望向每个单元格添加更多元素。进行了一些搜索,但找不到任何信息。唯一的方法是使用tableview复制它。除了textlabel.text,我还可以设置其他属性吗


提前谢谢

是,您可以设置cell.imageView、cell.accessoryView、cell.BackGroundView。。等等


阅读本文档了解更多信息

是,您可以设置cell.imageView、cell.accessoryView、cell.BackGroundView。。等等


阅读本文档以了解更多信息

非常可能。所有tableView数据源方法都使用tableView参数调用。如果

if (tableView == searchController.searchResultsTableView)

然后通过添加子视图或自定义属性来更改单元格。在这种情况下,与在任何其他情况下一样,相同的方法适用于自定义单元格。

非常可能。所有tableView数据源方法都使用tableView参数调用。如果

if (tableView == searchController.searchResultsTableView)

然后通过添加子视图或自定义属性来更改单元格。在这种情况下,与在其他情况下相同的方法适用于自定义单元格。

您可以完全更改单元格

下面的代码片段依赖于UITableCell的两个子类ANormalCell和ASearchCell

警告:这段代码还没有编译,但你明白要点了吗

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

    static NSString *normalCellReuseIdentifier = @"ANormalCell";
    static NSString *searchCellReuseIdentifier = @"ASearchCell";

    UITableViewCell* cell = nil;

    if (tableView != self.searchDisplayController.searchResultsTableView) {
        cell = (ANormalCell*)[self.tableView dequeueReusableCellWithIdentifier:normalCellReuseIdentifier];

        if (cell == nil) {
            NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ANormalCell" owner:nil options:nil];
            cell = (ANormalCell*)[topLevelObjects objectAtIndex:0];
        }
    } else {
        cell = (ASearchCell*)[self.tableView dequeueReusableCellWithIdentifier:searchCellReuseIdentifier];

        if (cell == nil) {
            NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ASearchCell" owner:nil options:nil];
            cell = (ASearchCell*)[topLevelObjects objectAtIndex:0];
        }
    }

    return cell;
}

您可以完全更改单元格

下面的代码片段依赖于UITableCell的两个子类ANormalCell和ASearchCell

警告:这段代码还没有编译,但你明白要点了吗

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

    static NSString *normalCellReuseIdentifier = @"ANormalCell";
    static NSString *searchCellReuseIdentifier = @"ASearchCell";

    UITableViewCell* cell = nil;

    if (tableView != self.searchDisplayController.searchResultsTableView) {
        cell = (ANormalCell*)[self.tableView dequeueReusableCellWithIdentifier:normalCellReuseIdentifier];

        if (cell == nil) {
            NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ANormalCell" owner:nil options:nil];
            cell = (ANormalCell*)[topLevelObjects objectAtIndex:0];
        }
    } else {
        cell = (ASearchCell*)[self.tableView dequeueReusableCellWithIdentifier:searchCellReuseIdentifier];

        if (cell == nil) {
            NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ASearchCell" owner:nil options:nil];
            cell = (ASearchCell*)[topLevelObjects objectAtIndex:0];
        }
    }

    return cell;
}

非常感谢您的回复!我正在设置detailtextlabel.text,但没有显示,因此我认为无法自定义单元格。我厌倦了imageview,它可以正常工作。顺便问一下,有没有办法在interface builder中自定义单元格,否则我将不得不以编程方式创建它?非常感谢您的回复!我正在设置detailtextlabel.text,但没有显示,因此我认为无法自定义单元格。我厌倦了imageview,它可以正常工作。顺便问一下,有没有办法在interface builder中自定义单元格,否则我将不得不以编程方式创建它?谢谢!我用的是故事板。我不认为只有一个单元格就可以创建nib。我检查了序列图像板,没有找到自定义uisearchdisplaycontroller单元格的方法。序列图像板和XIB可以一起使用(在同一个项目中),使用XIB设计自定义单元格是我个人经常做的事情。我遇到了类似的问题,这就解决了它。不同的是,搜索表似乎不允许我通过“table Registernb:forCellReuseIdentifier”使用自定义单元格,但是您的建议([[NSBundle mainBundle]loadNibNamed…)是的!谢谢!我正在使用序列图像板。我不认为有办法用一个单元格创建nib。我检查了序列图像板,但没有找到自定义uisearchdisplaycontroller单元格的方法。序列图像板和XIB可以一起使用(在同一个项目中)使用XIBs设计自定义单元格是我个人经常做的事情。我遇到了一个类似的问题,这就解决了它。不同的是,搜索表似乎不允许我通过“table Registernb:forCellReuseIdentifier”使用自定义单元格,但您的建议([[NSBundle mainBundle]loadNibNamed…)确实如此!