Ich habe diese Situation: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];
}
Die IBOutlet richtig verbunden ist, kann ich nicht verstehen, warum es den Fehler gibt. Einige Hinweise?
EDIT: Ich habe ssame Operationen in einer anderen App gemacht und es funktioniert perfekt; Ich kann immer noch nicht herausfinden, was den Absturz verursacht hat. Ich werde die komplette Funktion veröffentlichen. Wie in der Antwort erwähnt, wird das Ereignis auf "Wert geändert" behandelt. Diese ist die Testfunktion, die funktioniert:
- (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];
}
Sie haben einen Stack-Trace oder andere Ausgabe von der Konsole? –
CONSOLE Programm empfangenes Signal: "EXC_BAD_ACCESS". – IssamTP
STACK Trace 0x003a56b2 <+0574> mov 0x47b1f2 (% ebx)% EDX – IssamTP