私は、テーブルのヘッダーを一緒にスクロールさせようとしていますUITableView
。最終的に機能するようになりましたが、マップ ビューのすぐ下に空白が表示されるようになりました(スクリーンショットを参照)。テーブルヘッダーセクションのマップをテーブルと一緒にスクロールしたり、UIButton をユーザータッチでテーブルヘッダー内でトリガーしたりするのに苦労しました (UIButton は単にマップをフルスクリーンに拡張します)。
これに関連して、昨日スクロールとボタンタッチについて質問しました。それらは現在機能しています-コーディングはもっとうまくできると確信していますが、これは私が現時点で持っているものであり、これをできるだけ早く完了する必要があります. この空白の問題を解決できれば、後でコードをリファクタリングして最適化できます。
これを手伝ってくれてありがとう。
スクリーンショットのマップの下とテーブル ビューの上に空白があることに注意してください。テーブル ビューをマップに近づけたいのです。
私のviewDidLoad
:メソッドで
// mapview
self.topMapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 140)];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.height,self.view.frame.size.height)];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.tableView];
次にviewForHeaderInSection:
メソッドで(これをメソッドで行うことが提案され、viewDidLoad:
それを試しましたが、さらに問題が発生しました
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 140)];
UIButton *showMapButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
showMapButton.frame = CGRectMake(0.0, 0, 320.0, 140.0);
[showMapButton setTitle:@"show map" forState:UIControlStateNormal];
[showMapButton addTarget:self
action:@selector(mapDetailViewDisplay:)
forControlEvents:UIControlEventTouchDown];
[headerView addSubview:self.topMapView];
[headerView showMapButton];
self.tableView.tableHeaderView = headerView;
return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 140;
}