gpt4 book ai didi

ios - 没有通用 tableViewCell 的 UISearchBar

转载 作者:行者123 更新时间:2023-11-29 01:59:49 25 4
gpt4 key购买 nike

我按照这个例子在我的项目中设置一个 UISearchController: https://developer.apple.com/library/ios/samplecode/TableSearch_UISearchController/Introduction/Intro.html#//apple_ref/doc/uid/TP40014683-Intro-DontLinkElementID_2

在示例中,他们以编程方式设置了一个 tableViewCell 以用于主 TableView 和搜索结果,而我已经在主 TableView 和搜索结果的 TableView 中获得了我将要使用的单元格。

如果我在 mainTableView 和 searchResultsTableView 的 cellForRowAtIndexPath 中使用 Storyboard ID,则会发生崩溃:“无法使具有标识符 SearchResultCell 的单元格出列 - 必须为标识符注册一个 nib 或一个类,或者连接 Storyboard 中的原型(prototype)单元格”。

非常感谢任何帮助!

最佳答案

我的意思是创建一个像这样的 .xib:

enter image description here

配置单元格的UI并设置标识符,例如:tableID

enter image description here

为属性 (IBOutlet) 设置自定义类 dTableViewCell

enter image description here

然后声明该类的属性:

@property (nonatomic) dTableViewCell *tableCell;
@property (nonatomic) dSearchTableViewCell *tableCell;

然后在你的UITableViewDelegate中:

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

if (tableView == self.mainTableView)
{
static NSString *cellID = @"tableID";

//dTableViewCell.xib for mainTableView ]> example...
[tableView registerNib:[UINib nibWithNibName:@"dTableViewCell" bundle:nil] forCellReuseIdentifier:cellID];

self.tableCell = [tableView dequeueReusableCellWithIdentifier:cellID];
}
else //searchTableView
{
static NSString *cellSearchID = @"searchTableID";

//dSearchTableViewCell.xib for searchTable ]> example...
[tableView registerNib:[UINib nibWithNibName:@"dSearchTableViewCell" bundle:nil] forCellReuseIdentifier:cellSearchID];

self.searchTableCell = [tableView dequeueReusableCellWithIdentifier:cellID];
}

}

还要检查 Storyboard 中的 SearchResultCell 标识符,因为崩溃告诉您 SearchResultCell 未注册。希望我能帮助您。祝编码愉快..

关于ios - 没有通用 tableViewCell 的 UISearchBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30494421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com