0

私は、テーブルのヘッダーを一緒にスクロールさせようとしています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;
    }
4

3 に答える 3

2

[UITableView tableHeaderView]とは異なりviewForHeaderInSectionますが、両方に同じオブジェクトを設定しています。

達成しようとしている動作の種類に応じて、viewForHeaderInSection デリゲート メソッドを介して headerView を設定self.tableView.tableHeaderViewするか、返す必要があります。viewDidLoad:

于 2013-10-29T11:31:04.380 に答える
1

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section残すだけですべてのコードを移動してみてくださいreturn headerView

viewDidLoad

変更する

UIView *headerView = [[UIView alloc] init];  

それ以外の

UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 140)];
于 2013-10-29T11:27:00.713 に答える