我目前有一個奇怪的問題。 我有一個pickerView與兩個按鈕(取消,並確定)的動作表。 他們工作完美,直到我選擇一個值在該選擇器,我點擊我的TabBarController包含我的NavigationController的第一個按鈕。帶有TabBarController的NavController中的ActionSheet - Exc_Bad_Access
我的動作表是在我的.h中聲明的,並且具有屬性(非原子,保留),我在我的dealloc函數中釋放它。
我有一個exc_bad_access如果我釋放這個對象,我不知道爲什麼,因爲我分配它。
這是我的函數,它創建我的工作表,如果是零,並建立它。
- (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)];
}
我也檢查指針爲nil在dealloc方法....
感謝
你能提供完整的EXEC_BAD_ACCESS錯誤日誌?如果您在調試器下運行程序,堆棧跟蹤包含什麼? – sergio