2011-07-23 10 views
0

私は現在、奇妙な問題があります。 私は2つのボタン(キャンセル、そしてOK)でpickerViewのアクションシートを持っています。 それらはピッカーで値を選択し、NavigationControllerを含むTabBarControllerの最初のボタンをクリックするまで完全に動作します。TabBarControllerを使用したNavControllerのアクションシート - Exc_Bad_Access

私のアクションシートは、私の.hで宣言されており、(非原子的な、保持している)プロパティを持っています。私は自分のdealloc関数でそれを解放します。

私はこのオブジェクトをリリースすれば私はexc_bad_accessを持っています。なぜ私がそれを割り当てたのか分かりません。

これは、nilの場合にアクションシートを作成してビルドする機能です。

- (IBAction)select_marque :(id)sender 
{ 
    if (!actionSheet_marque) 
    { 
     actionSheet_marque = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 
    } 
    [actionSheet_marque setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

    CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 


    picker_marque = [[UIPickerView alloc] initWithFrame: pickerFrame]; 
    picker_marque.showsSelectionIndicator = YES; 
    picker_marque.dataSource = self; 
    picker_marque.delegate = self; 

    [actionSheet_marque addSubview: picker_marque]; 

    [picker_marque release]; 

    UILabel *lbl = [[UILabel alloc] initWithFrame: CGRectMake(110, 7.0f, 150.0f, 30.0f)]; 
    lbl.text = @"Marque"; 
    lbl.backgroundColor = [UIColor clearColor]; 
    lbl.textColor = [UIColor whiteColor]; 

    [actionSheet_marque addSubview:lbl]; 

    [lbl release];  

    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Ok"]]; 
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    closeButton.tintColor = [UIColor blueColor]; 
    [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged]; 

    [actionSheet_marque addSubview:closeButton]; 

    [closeButton release]; 

    UISegmentedControl *cancelButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Cancel"]]; 
    cancelButton.momentary = YES; 
    cancelButton.frame = CGRectMake(5, 7.0f, 50.0f, 30.0f); 
    cancelButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    cancelButton.tintColor = [UIColor redColor]; 
    cancelButton.tag = 1; 
    [cancelButton addTarget:self action:@selector(cancelActionSheet:) forControlEvents:UIControlEventValueChanged]; 

    [actionSheet_marque addSubview:cancelButton]; 

    [cancelButton release]; 

    [actionSheet_marque showInView: self.navigationController.view]; 

    [actionSheet_marque setBounds:CGRectMake(0, 0, 320, 485)]; 
} 

ポインタはdeallocメソッドでnilである場合、私はあなたがUIActionsheetの性質を持っている場合は、それを割り当てるとき

おかげ

+0

は、あなたが完全なEXEC_BAD_ACCESSエラーログを提供することができれば、この行を除いて、この

if (!actionSheet_marque) { self.actionSheet_marque = [[[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil] autorelease]; } [self.actionSheet_marque setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

全体の機能のようにコードを変更してみてください?デバッガでプログラムを実行すると、スタックトレースには何が含まれますか? – sergio

答えて

0

は、あなたがself.actionSheet_marqueを使用する必要があります....も確認してください。 (!actionSheet_marque)

+0

'self.retainOrCopyProperty = alloc-init'がリークします。 alloc-initは所有しているオブジェクトを返し、retainプロパティはオブジェクトの所有権を再度要求します。その結果、オブジェクトが過剰保持されます。 – albertamg

+0

申し訳ありません私は彼に最後にオートレアを入れて言うことを忘れてしまいます。私は答えを編集しました。 –

+0

あなたの答えをありがとう、私はあなたのアイデアを試してみます。私はObjective-Cの初心者です。もし私のActionSheet_Marqueが私のクラスにあれば、私は私の.mでそれを割り当てた場合、私は留守番や特産品を持っていないかもしれません。第二に、変数にいくつかのプロパティを行う場合、私はそれを割り当てたときにself.VarNameを行う必要がありますか? (私の貧しい英語のスキルのために私はフランス語です) – Morgan

関連する問題