<tfoot id='8PDB7'></tfoot>

        <bdo id='8PDB7'></bdo><ul id='8PDB7'></ul>
      <legend id='8PDB7'><style id='8PDB7'><dir id='8PDB7'><q id='8PDB7'></q></dir></style></legend>
    1. <i id='8PDB7'><tr id='8PDB7'><dt id='8PDB7'><q id='8PDB7'><span id='8PDB7'><b id='8PDB7'><form id='8PDB7'><ins id='8PDB7'></ins><ul id='8PDB7'></ul><sub id='8PDB7'></sub></form><legend id='8PDB7'></legend><bdo id='8PDB7'><pre id='8PDB7'><center id='8PDB7'></center></pre></bdo></b><th id='8PDB7'></th></span></q></dt></tr></i><div id='8PDB7'><tfoot id='8PDB7'></tfoot><dl id='8PDB7'><fieldset id='8PDB7'></fieldset></dl></div>

        <small id='8PDB7'></small><noframes id='8PDB7'>

      1. 如何将基于故事板的 Header 和 CustomTableCell 添加到“搜索栏和搜索显示控制器"

        时间:2023-06-10

          <i id='eR1TA'><tr id='eR1TA'><dt id='eR1TA'><q id='eR1TA'><span id='eR1TA'><b id='eR1TA'><form id='eR1TA'><ins id='eR1TA'></ins><ul id='eR1TA'></ul><sub id='eR1TA'></sub></form><legend id='eR1TA'></legend><bdo id='eR1TA'><pre id='eR1TA'><center id='eR1TA'></center></pre></bdo></b><th id='eR1TA'></th></span></q></dt></tr></i><div id='eR1TA'><tfoot id='eR1TA'></tfoot><dl id='eR1TA'><fieldset id='eR1TA'></fieldset></dl></div>
            • <legend id='eR1TA'><style id='eR1TA'><dir id='eR1TA'><q id='eR1TA'></q></dir></style></legend>
              • <bdo id='eR1TA'></bdo><ul id='eR1TA'></ul>
                  <tbody id='eR1TA'></tbody>
                <tfoot id='eR1TA'></tfoot>

                  <small id='eR1TA'></small><noframes id='eR1TA'>

                • 本文介绍了如何将基于故事板的 Header 和 CustomTableCell 添加到“搜索栏和搜索显示控制器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  演示文稿

                  我的是一个简单的项目:它由一个 NavigationController、ViewController 和一个搜索栏和搜索显示控制器"组成

                  Mine is a simple project: It consists of a NavigationController, ViewController, and a "Search Bar and Search Display Controller"

                  我的 .h 文件是

                  #import <UIKit/UIKit.h>
                  
                  @interface ViewController : UIViewController <UISearchDisplayDelegate, UITableViewDataSource, UITableViewDelegate>
                  
                  @end
                  

                  而我的 .m 文件是

                  #import "ViewController.h"
                  
                  @interface ViewController ()
                  @property(nonatomic,strong)NSMutableArray *data;
                  @end
                  
                  @implementation ViewController
                  
                  - (void)viewDidLoad
                  {
                      [super viewDidLoad];
                      // Do any additional setup after loading the view, typically from a nib.
                      self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
                      self.data=[[NSMutableArray alloc]init];
                  }
                  
                  - (void)didReceiveMemoryWarning
                  {
                      [super didReceiveMemoryWarning];
                      // Dispose of any resources that can be recreated.
                  }
                  
                  
                  #pragma mark - data source
                  
                  - (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
                      // Return the number of sections.
                      return 1;
                  }
                  
                  - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
                      // Return the number of rows in the section.
                      return [_data count];
                  }
                  
                  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
                  
                      static NSString *CellIdentifier = @"CellIdentifier";
                  
                      // Dequeue or create a cell of the appropriate type.
                      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                      if (cell == nil) {
                          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
                          cell.accessoryType = UITableViewCellAccessoryNone;
                      }
                  
                      // Configure the cell.
                      cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];
                      cell.textLabel.text = [NSString stringWithFormat:@"Row %d: %@", indexPath.row, [_data objectAtIndex:indexPath.row]];
                      return cell;
                  }
                  
                  #pragma mark - delegate
                  
                  - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
                  {
                      [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(mockSearch:) userInfo:searchString repeats:NO];
                      return NO;
                  }
                  
                  - (void)mockSearch:(NSTimer*)timer
                  {
                      [_data removeAllObjects];
                      int count = 1 + random() % 20;
                      for (int i = 0; i < count; i++) {
                          [_data addObject:timer.userInfo];
                      }
                      [self.searchDisplayController.searchResultsTableView reloadData];
                  }
                  
                  @end
                  

                  这就是整个程序.它有什么作用?用户进行搜索,数据显示在 TableView 中(类似于 google 搜索).

                  And that’s the entire program. What does it do? User makes a search and the data is displayed in a TableView (similar to a google search).

                  问题

                  • 我需要为我的表格使用 CustomTableViewCell.我需要从情节提要构建 TableViewCell(易于可视化).我被故事板部分困住了.如何在没有 TableView 的情况下将 TableViewCell 放置在情节提要上?我有一个想法,我尝试过,但没有成功.这就是我所做的.我在情节提要中放置了一个永远不会被使用"的 TableViewController,其唯一目的是保存我的 CustomTableViewCell.然后在代码中,我将 TableViewCell 子类化并使用 IBOutlet 将情节提要 TableViewCell 的子视图链接到我的 CustomTableViewCell .然后我将我的单元格用作 CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];.这没有用.tableView 保持空白.而我对失败的猜测是 CustomTableViewCell 不属于正在出队的 tableView.

                  • I need to use a CustomTableViewCell for my table. And I need to build the TableViewCell from the storyboard (easy to visualize). I am stuck with the storyboard part. How do I place a TableViewCell on the storyboard without a TableView to place it in? I had an idea, I tried it, but it didn’t work. Here is what I did. I placed a "never-to-be-used" TableViewController in the storyboard whose sole purpose is to hold my CustomTableViewCell. Then in code I subclass TableViewCell and use IBOutlet to link the sub-views of the storyboard TableViewCell to my CustomTableViewCell . And then I used my cell as CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];. This didn’t work. The tableView remained blank. And my guess for the failure is that CustomTableViewCell does not belong to the tableView being dequeued from.

                  我需要 UISearchBar 始终留在 NavigationBar 内.但到目前为止 self.searchDisplayController.displaysSearchBarInNavigationBar = YES; 并没有这样做.当我第一次启动应用程序时,搜索栏位于导航栏内.但只要我点击它,它就会在我的场景/屏幕中间撞到自己,永远不会离开.

                  I need the UISearchBar to always stay inside the NavigationBar. But so far self.searchDisplayController.displaysSearchBarInNavigationBar = YES; is not doing it. When I first start the app the searchBar is inside the NavigationBar. But as soon as I click on it, it smacks itself right in the middle of my scene/screen and never leaves.

                  我需要在我的 TableView 中添加一个 Header.我想用与 CustomTableViewCell 相同的方式,但使用 UIView 父类.但同样,CustomTableViewCell 部分失败了.

                  I need to add a Header to my TableView. Which I thought of doing the same way as the CustomTableViewCell, but with a UIView parent class. But again, the CustomTableViewCell portion failed.

                  恳求

                  感谢您为我提供的任何帮助.

                  Thank you for any help you can provide me.

                  更新

                  我想做的只是让我的用户启动服务器端搜索并在 tableView 中查看结果.这是一个基本的事情,我想这里的很多人都做过很多次.作为iOS新手,我被困住了.但是此时,我已经发布了我的整个项目(任何人都可以重建它),并且我已经详细解释了我试图解决问题的所有方法.因此,如果有人有一个他们不介意分享的示例项目,那将非常有帮助.或者如果你知道一个 git 项目,请给它一个链接.谢谢.

                  All I am trying to do is allow my users to launch a server side search and view the results in a tableView. This is such a basic thing, I image many people here have done this a number of times. Being new to iOS, I am stuck. But at this point, I have posted my entire project (anyone can reconstruct it), and I have explained in details all the ways I tried to solve the problem. So if someone has a sample project they don’t mind sharing, it would help very much. Or if you know of a git project please put a link to it. Thanks.

                  推荐答案

                  如果你想在 IB 中创建一个独立的视图(不在视图控制器中),那么你应该在 xib 文件中进行,而不是在故事板中进行.您可以在应用程序中拥有任意数量的故事板和 xib 文件;它们可以自由混合.要在 xib 文件中创建新单元格,只需转到新建文件 --> 用户界面 --> 空,然后拖入 UITableViewCell.添加您想要的任何子视图,然后在您的表格视图控制器(或您的表格视图数据源的任何类)中,使用 registerNib:forIdentifier 注册 xib 文件:(通常,您在 viewDidLoad 中执行此操作).

                  If you want to make a stand-alone view (not in a view controller) in IB, then you should do it in a xib file, not a storyboard. You can have as many storyboard and xib files in an app as you want; they can be mixed freely. To make a new cell in a xib file, just go to New File --> User Interface --> Empty then drag in a UITableViewCell. Add any subviews you want, and in your table view controller (or whatever class is your table view data source), register the xib file with, registerNib:forIdentifier: (usually, you do this in viewDidLoad).

                  这篇关于如何将基于故事板的 Header 和 CustomTableCell 添加到“搜索栏和搜索显示控制器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么我的视图仍然以横向显示? 下一篇:iphone facebook 应用程序如何修复导航栏

                  相关文章

                  <legend id='JJEYX'><style id='JJEYX'><dir id='JJEYX'><q id='JJEYX'></q></dir></style></legend>

                  1. <small id='JJEYX'></small><noframes id='JJEYX'>

                  2. <tfoot id='JJEYX'></tfoot>
                      • <bdo id='JJEYX'></bdo><ul id='JJEYX'></ul>
                      <i id='JJEYX'><tr id='JJEYX'><dt id='JJEYX'><q id='JJEYX'><span id='JJEYX'><b id='JJEYX'><form id='JJEYX'><ins id='JJEYX'></ins><ul id='JJEYX'></ul><sub id='JJEYX'></sub></form><legend id='JJEYX'></legend><bdo id='JJEYX'><pre id='JJEYX'><center id='JJEYX'></center></pre></bdo></b><th id='JJEYX'></th></span></q></dt></tr></i><div id='JJEYX'><tfoot id='JJEYX'></tfoot><dl id='JJEYX'><fieldset id='JJEYX'></fieldset></dl></div>