我有这种情况:UISegmentedControl EXC_BAD_ACCESS
// CustViewController.h
...
IBOutlet UISegmentedControl *sgmController;
...
@property (nonatomic, retain) IBOutlet UISegmentedControl *sgmController;
// CustViewController.m
@synthesize sgmController;
- (IBAction)apriRassegnePrecedenti {
NSString *model;
NSString *nibToLoad;
UIBarButtonItem *backBarButtonItem;
VecchieRassegneViewController *vecchieRassegne;
if (self.sgmRassegna.selectedSegmentIndex == 1) {
backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Rass. odierne" style:UIBarButtonItemStylePlain target:self action:nil];
model = [NSString stringWithString:[[UIDevice currentDevice] model]];
if ([model isEqualToString:@"iPhone"] || [model isEqualToString:@"iPhoneSimulator"]) {
nibToLoad = [NSString stringWithString:@"VecchieRassegneViewController"];
} else {
nibToLoad = [NSString stringWithString:@"VecchieRassegneViewControllerPAD"];
}
vecchieRassegne = [[VecchieRassegneViewController alloc] initWithNibName:nibToLoad bundle:nil];
self.sgmRassegna.selectedSegmentIndex = 0; // The Crash comes here.
[self.navigationController pushViewController:vecchieRassegne animated:YES];
}
[backBarButtonItem release];
[vecchieRassegne release];
}
的IBOutlet中链接正确,我想不通为什么它给人的错误。 一些提示?
编辑:我已经在另一个应用程序中完成ssame操作,它完美地工作;我仍然无法确定导致事故的原因。我会发布完整的功能。 正如答案中所述,该事件在“值已更改”上处理。 这是测试功能的工作原理:
- (IBAction)pushDiTest {
ASecondView *secondView;
secondView = [[ASecondView alloc] initWithNibName:@"ASecondView" bundle:nil];
if (self.sgmTest.selectedSegmentIndex == 1) {
self.sgmTest.selectedSegmentIndex = 0;
[self.navigationController pushViewController:secondView animated:YES];
}
[secondView release];
}
你有一个堆栈跟踪或控制台的其他输出? – 2010-12-03 17:30:04
CONSOLE编程接收信号:“EXC_BAD_ACCESS”。 – IssamTP 2010-12-03 17:45:08