NavController 中的 ActionSheet 与 TabBarController - Exc_Bad_Access

发布于 2024-11-26 00:13:51 字数 2502 浏览 1 评论 0原文

我目前有一个奇怪的问题。 我有一个带有 pickerView 的操作表,其中有两个按钮(取消和确定)。 它们完美地工作,直到我在该选择器中选择一个值并单击包含我的 NavigationController 的 TabBarController 的第一个按钮。

我的操作表在我的 .h 中声明并具有属性(非原子,保留),我在我的 dealloc 函数中释放它。

如果我释放这个对象,我就会有一个 exc_bad_access ,但我不知道为什么,因为我分配了它。

这是我的函数,它创建我的 Actionsheet(如果为零)并构建它。

- (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方法中的指针是否为零......

谢谢

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 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-12-03 00:13:51

如果您有 UIActionsheet 属性,那么您在分配它时应该使用 self.actionSheet_marque 。尝试更改这样的代码

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


    [self.actionSheet_marque setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

在整个函数中,除了这一行 if (!actionSheet_marque)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文