Objective c NavController中带有TabBarController的操作表-Exc_错误访问
我现在有一个奇怪的问题。 我有一个带有pickerView的操作表,其中有两个按钮(取消和确定)。 在我在选择器中选择一个值并单击包含NavigationController的TabBarController的第一个按钮之前,它们工作得非常好 我的操作表在My.h中声明,并具有属性(非原子,retain),我在dealloc函数中释放它 如果我释放这个对象,我有一个exc_bad_访问权限,我不知道为什么,因为我分配了它 这是我的函数,如果为nil,则创建我的操作表,并构建它Objective c NavController中带有TabBarController的操作表-Exc_错误访问,objective-c,uipickerview,exc-bad-access,uiactionsheet,Objective C,Uipickerview,Exc Bad Access,Uiactionsheet,我现在有一个奇怪的问题。 我有一个带有pickerView的操作表,其中有两个按钮(取消和确定)。 在我在选择器中选择一个值并单击包含NavigationController的TabBarController的第一个按钮之前,它们工作得非常好 我的操作表在My.h中声明,并具有属性(非原子,retain),我在dealloc函数中释放它 如果我释放这个对象,我有一个exc_bad_访问权限,我不知道为什么,因为我分配了它 这是我的函数,如果为nil,则创建我的操作表,并构建它 - (IBActi
- (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的属性,那么您应该在分配它时使用self.actionSheet\u-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];
如果(!actionSheet_marque)
self.retainOrCopyProperty=alloc init
泄漏,则在除此行之外的整个函数中。alloc init返回您拥有的对象,并且retain属性再次声明该对象的所有权,这导致该对象被过度保留。抱歉,我忘了告诉他将autorelease放在最后。我已经编辑了答案。谢谢你的回答,我会试试你的想法。我是一个新手,没有目标C。如果我的行动表在我的班上,我可能不会保留或做适当的事情,如果我把它分配到我的.m?第二,如果我对一个变量做了一些属性,那么当我分配它时,我必须做self.VarName吗?(请原谅我英语不好,我是法国人)@Morgan没问题,伙计,请参考这些链接了解objective-C2.0属性1。2.3.我最喜欢的文章()你能提供完整的EXEC\u BAD\u访问错误日志吗?如果在调试器下运行程序,堆栈跟踪包含什么?