免責事項: 私は 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
ここで何を誤解しましたか?
ありがとう