UISearchbar 与 UIStoryboard:segues 和自定义单元格无法正常工作
我正在使用情节提要,并想为我的 UITableView 实现 UISearchbar。 UISearchbarController 生成一个新的 UITableView,我使用以下策略:
if (tableView == self.tableView)
//Populate table view with normal data
else
//Populate table view with search data
第一个问题是处理自定义单元格。我必须在 cellForRowAtIndexPath 中实例化它们。通常,您可以从 nib 文件执行此操作。我如何通过故事板做到这一点? dequeueReusableCellWithIdentifier 返回 nil。
第二个问题涉及从表视图到详细视图的连接。 Segue 在普通表视图中启动,但不在搜索表视图中启动。由于故事板隐藏了所有内容,我不知道如何将 Segues 分配给搜索表视图的单元格。
有人可以帮忙吗?谢谢!
I am using storyboards and want to implement a UISearchbar for my UITableView. The UISearchbarController generates a new UITableView and I use the following strategy:
if (tableView == self.tableView)
//Populate table view with normal data
else
//Populate table view with search data
The first problem is to deal with custom cells. I have to instantiate them in cellForRowAtIndexPath. Normally you would do that from a nib file. How do I do this from with storyboards? dequeueReusableCellWithIdentifier returns nil.
The second problem concerns the segue from the table view to the detail view. The segue is initiated in the normal table view, but not in the search table view. Since Storyboards hides everything I have no idea how to assign segues to cells of the search table view.
Could anyone help, please? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于第一个问题,我通过将 ViewController 类型从 UITableViewController 更改为 UIViewController 解决了它,然后在其中添加表视图并为表视图添加 IBOutlet
使用出口使表单元格出队
Regarding the first problem i solved it by changing the ViewController type from UITableViewController to UIViewController , then adding table view inside it and add IBOutlet for the table view
use the outlet to dequeue the table cell
关于第二个问题:不要从单元格链接segue,而是从视图控制器链接segue。您需要在故事板中使用不同的名称创建两个 segue。然后在选择该行时手动调用 segue:
About the second problem: don't link the segue from the cell, but from the viewcontroller. You will need to make two segues in your storyboard with different names. Then manually invoke the segue when the row is selected:
所以这就是我所做的:
1)我在 initWithStyle:reuseIdentifier: 中初始化了自定义单元格,然后在layoutSubviews中实现了布局。所以我仍然不知道如何从故事板加载单元格。
2)我将视图推送到导航堆栈上,而不是使用故事板转场。
So here is what I did:
1) I initialized the custom cells in initWithStyle:reuseIdentifier:, then implemented the layout in layoutSubviews. So I still have no idea how to load the cells from the storyboards.
2) I pushed the view on the navigation stack instead of using the storyboard segues.