【问题标题】:UISearchBar without a common tableViewCell没有通用 tableViewCell 的 UISearchBar
【发布时间】:2015-08-10 05:52:35
【问题描述】:
【问题讨论】:
标签:
ios
objective-c
xcode
uitableview
uisearchbar
【解决方案1】:
我的意思是像这样创建一个 .xib:
配置单元格的UI 并设置标识符,例如:tableID
为属性(IBOutlet)设置自定义类dTableViewCell
然后为类声明一个属性:
@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];
}
}
还要检查你的故事板中的 SearchResultCell 标识符,因为崩溃告诉你 SearchResultCell 没有注册。希望我能帮助你。祝你编码愉快。