开发者

ActionSheet in NavController with TabBarController - Exc_Bad_Access

I'm currently have a weird problem. I have an actionsheet with pickerView in with two button (cancel, and Ok). They work perfectly until i choose a value in that picker and i click on the first button of my TabBarController which contain my NavigationController.

My actionsheet is declared in my .h and has property (nonatomic, retain), i release it in my dealloc function.

I have an exc_bad_access if i release this object and i dont know why because i allocated it.

This is my function which create my Actionsheet if is nil, and build it.

- (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开发者_JS百科 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)];
}

I check also if the pointer is nil in dealloc method....

Thanks


If you have property of UIActionsheet then you should use self.actionSheet_marque when you allocate it. Try changing code like this

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


    [self.actionSheet_marque setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

And in whole function except this line if (!actionSheet_marque)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜