I have an IBAction in my project, when user presses button, it should load a new view controller, however the code seems to be crashing
My code is as follows:
- (IBAction)PurchaseItem:(id)sender {
PurchasedViewController *purchaseContr = (PurchasedViewController *)
[self.storyboard instantiateViewControllerWithIdentifier:@"ShowAd"];
_purchaseController.productID = @"com.id";
purchaseContr.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:purchaseContr animated:YES completion:NULL];
}
When I run the app on the device and press the button, the app crashed on the following line:
[self presentViewController:purchaseContr animated:YES completion:NULL];
The message I Have got is 'Thread 1: breakpoint 1.3'
My Crashlog is:
If you're looking for the right way to use Storyboards and Segues...
CTRL
and click-drag from the originating view controller to the destination view controller. This creates and unnamed segue from A to B. -(IBAction)purchasItem:(id)sender {
[self performSegueWithIdentifier:@"ShowAD" sender:self];
}
Now, to set a property on the destination view controller, add another method to your originating view controller as such:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowAD"]) {
PurchasedViewController *purchaseContr = [segue
destinationViewController];
purchaseContr.productID = @"com.id";
}
}
Now... with all this said, I think the problem actually is that you've manually set a break point. If you've got a little blue arrowish thing where the line numbers are, that's a manually added breakpoint. It stops your program execution at that line... but it's not a crash. You can right click the breakpoint and click "disable" or "delete" breakpoint, and it'll "fix" your "crash".
This isn't a crash, it looks like a manually set breakpoint! Disable all breakpoints in Xcode and run again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.