0

使うviewForFooterInSectionときだから使う

tableView.tableFooterView = footerView;

私のボタンはタッチできません。そのため、最後のセクションがどこにあるかを手動で示したいと思います。

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

   if(control.selectedSegmentIndex == 1 && section == 1)
   {
if(myFooterView == nil) {
    //allocate the view if it doesn't exist yet
    myFooterView  = [[UIView alloc] init];


    //create the button
    UIButton *footButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [footButton setFrame:CGRectMake(110, 10, 100, 30)];

    //set title, font size and font color
    [footButton setTitle:@"Go Home" forState:UIControlStateNormal];
    [footButton.titleLabel setFont:[UIFont boldSystemFontOfSize:18]];

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

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

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

このコード行は私にEXC_BAD_ACCESSエラーを与えています、そして私はセクションが存在すると確信しています:

if(control.selectedSegmentIndex == 1 && section == 1)

何が問題なのかわかりません。

編集:

@property (nonatomic, retain) UISegmentedControl *control;


- (void)viewWillAppear:(BOOL)animated
{
[self setTitle:_actor.actorNaam];
NSLog(@"Actor viewwillappear %@", _actor.actorNaam);

NSArray *items = [[NSArray alloc] initWithObjects: @"Actor", @"Object", @"Operation", @"Goal", nil];
control = [[UISegmentedControl alloc] initWithItems:items]; //!!!!!!!!!!!!!!!
control.selectedSegmentIndex = segmentPushed;
control.segmentedControlStyle = UISegmentedControlStylePlain;
control.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
control.apportionsSegmentWidthsByContent = YES;
4

1 に答える 1

0

ARC環境を利用している前提で、

「コントロール」を保持として宣言しましたが、割り当て方法が不適切なため、ARC環境に保持されていません。

変える:

control = [[UISegmentedControl alloc] initWithItems:items];

使用する

self.control = [[UISegmentedControl alloc] initWithItems:items];

selfを使用すると、デフォルトのセッターが呼び出され、現時点では行われていないオブジェクトが保持されます。

于 2013-02-19T12:31:21.043 に答える