0

私は uitableview を持っており、テーブルには異なるセクションがあり、各セクションには異なる行があり、各セクションの最後の行にボタンを 1 つ追加したい

私は sectionFooter を使用しましたが、ここに私のコードがありますが、テーブルの最後のセクションにあるだけで、スクロールしても表示されない理由がわかりません。

これが私のコードです:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

return 50;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

if(footerView == nil) {

    footerView  = [[UIView alloc] init];


    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

  //  [button setBackgroundImage:image forState:UIControlStateNormal];

    //the button should be as big as a table view cell
    [button setFrame:CGRectMake(10, 3, 300, 44)];

    //set title, font size and font color
    [button setTitle:@"Report New Time" forState:UIControlStateNormal];
    [button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];

    //set action of the button
    [button addTarget:self action:@selector(removeAction:)
     forControlEvents:UIControlEventTouchUpInside];

    //add the button to the view
    [footerView addSubview:button];
}

//return the view for the footer
return footerView;
}

ここで何が問題なのですか、助けてください!

前もって感謝します!

4

3 に答える 3

0

1 つの UIView は 1 つのスーパービューのみを持つ必要があります。セクションごとに footerView を作成する必要があります。

于 2012-08-07T07:05:09.040 に答える
0

tableView:viewForFooterInSection: メソッドの if ステートメントを削除する必要があります。これにより、ビューが 1 つだけ作成されます。

于 2012-08-07T07:20:45.503 に答える
0

footerViewfor every セクションを再利用していfooterViewます。一部はインスタンス変数を 1 つ保持するだけで、一部は一度作成するだけです。セクションのフッター ビューを要求され、同じビューが返されるたびUITableViewに、そのビューはすべての場所に同時にとどまることはできないため、移動されます。解決策は、単一のビューを使用しないことです。

an を使用して、セクション番号をキーとして sNSMutableDictionaryを保持し、適切なフッター ビューを値として保持します。NSNumber単一のインスタンス変数ではなく、ディクショナリ内のセクションの「スロット」で動作するようにコードを変更します。

于 2012-08-07T07:28:50.173 に答える