1

免責事項: 私は iOS n00b のようなものです。ナビゲーション ベースのアプリがあります。つまり、AppDelegate でナビゲーション フレームを作成します。

self.navigation_controller = [[UINavigationController alloc] initWithRootViewController:home_view_controller];
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.rootViewController = navigation_controller;
self.window.makeKeyAndVisible;

ホーム ビューのフレーム内に検索バーが必要で、次にスクロール可能なテーブル ビューが必要です。だから、私はこれを書いた:

- viewDidLoad{
  (HomeView*)home_view = [[HomeView alloc] init];
  self.view = home_view
  self.view.backgroundColor = [UIColor whiteColor]

  (UITableView*)self.table_view = [UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  self.table_view.bounds.origin.y += 44;
  self.table_view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  self.table_view.dataSource = self;
  self.table_view.delegate = self;
  [self.view addSubview:self.table_view];

  search_frame = self.view.bounds;
  search_frame.origin.y = 48.0;
  search_frame.size.height = 48.0;

  self.search_bar = [[UISearchBar alloc] initWithFrame:search_frame)];
  [self.view addSubview:self.search_bar];
}

テーブル ビューは正常に表示されますが、ナビゲーション バーの下のすべてのスペースを占有します。ナビゲーション バーが必要で、そのすぐ下に検索バーがあり、その後にテーブル ビューが続きます。の時点ではviewDidLoad、 にUITableViewはまだゼロ以外の境界矩形がなく、それが問題の一部であると予想されます。さらに、検索バーに貼り付けたいときに指定UIViewAutoresizingFlexibleHeightしました。これも問題の一部である可能性があります。autoresizingMask

ここで何を誤解しましたか?

ありがとう

4

2 に答える 2

1

スティーブ、

次の変更を試してください。

1) 以下を使用してテーブルビューのフレームを設定します。

CGRect targetRect = CGRectMake(0, 48, self.view.frame.size.width, self.view.frame.size.heigth);
(UITableView*)self.table_view = [UITableView alloc] initWithFrame:targetRect style:UITableViewStylePlain];

2) 次のオートサイズ マスクも追加します。

// This value will anchor your table view with top margin
UIViewAutoresizingFlexibleBottomMargin

3) 検索バーのフレームを次の rect フレームに設定します。

CGRecttMake(0, 0, self.view.frame.size.width, 48);
于 2012-06-15T19:14:37.060 に答える
0

私がすることは、UISearchBarを最初のUITableViewヘッダーとして追加することです。

(方法tableView:viewForHeaderInSection::)

このブログ投稿を確認してください:http: //jainmarket.blogspot.com/2009/08/add-searchbar-as-uitableviews-header.html

于 2012-06-15T19:01:17.677 に答える