Thread 1: EXC_BREAKPOINT (code=EXC_i386_BPT, subcode=0x0) error - objective-c

I have an iPad app I am making, but it crashes on startup even though there are no errors or warnings, the output doesn't output anything besides "(lldb)", and it marks a pointer.
This is the image of the post build crash.
And here is the code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* UIImage *myImage = [UIImage imageNamed:#"de_dust2.png"];
myImageView = [[UIImageView alloc] initWithImage:myImage];
myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 0.75;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
// [myScrollView addSubview:myImageView];*/
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.viewController setRed:1];
[self.viewController setGreen:0];
[self.viewController setBlue:0];
[self.viewController setAlpha:1];
[self.viewController checkRotation];
return YES;
}
I now also noticed that the error was given at the [self.window makeKeyAndVisible]; line.

Your code looks ok, the crash could be caused by some exception thrown parsing the XIB file of the window ...
Take a look at the Window in Interface Builder and try to temporary remove all reference to any IBOutlet present in the View Controller ...

Related

Second UIScreen causing problems with UIStoryboards

In my app delegate i set up another screen (for airPlay).
When i create a second window and assign the Second screen to it and run the app the TableView in my storyboard turns to a black colour. Its as if the tableView is not rendering correctly. I have isolated the problem to :
self.HDTVwindow.screen=[[UIScreen screens] objectAtIndex:1];
where the HDTVWindow is the second window for my airplay app. When i comment out this code the storyboard runs fine and my UITableView is nice and white. Am i confusing the storyboard by making two UIWindows in the appDelegate, even though they are assigned to different screens??
For my appDelegate see below.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[UIScreen screens] count]>1)
{
CGRect frame = [[UIScreen screens]objectAtIndex:1].bounds;
self.HDTVwindow = [[UIWindow alloc] initWithFrame:frame];
UIImage* astonLogo=[UIImage imageNamed:#"AstonUni720p.png"];
UIImageView* astonLogoView=[[UIImageView alloc] initWithImage:astonLogo];
astonLogoView.frame=frame;
[self.HDTVwindow addSubview:astonLogoView];
self.HDTVwindow.hidden = NO;
self.HDTVwindow.screen=[[UIScreen screens] objectAtIndex:1];//PROBLEM!!
}
// Set Up Storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *mainViewController = [storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = mainViewController;
[self.window makeKeyAndVisible];
return YES;
}
The problem disapears when ran with the iPad and an apple TV, it seems there might a bug in the simulator. In future i shall always run my code on real ios devices.

How to deal with storyboard instead of xib file in such case?

I have an example where I have animation when the app starts. At the start an image is displayed, then moves from right to left, then disappears. Below is the code I have.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewwController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewwController;
[self.window makeKeyAndVisible];
//add the image to the forefront...
UIImageView *splashImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[splashImage setImage: [UIImage imageNamed:#"Default"]];
[self.window addSubview:splashImage];
[self.window bringSubviewToFront:splashImage];
//set an anchor point on the image view so it opens from the left
splashImage.layer.anchorPoint = CGPointMake(0, 0.5);
//reset the image view frame
splashImage.frame = CGRectMake(0, 0, 320, 480);
//animate the open
[UIView animateWithDuration:1.0
delay:0.6
options:(UIViewAnimationCurveEaseOut)
animations:^{
splashImage.layer.transform = CATransform3DRotate(CATransform3DIdentity, -M_PI_2, 0, 1, 0);
} completion:^(BOOL finished){
//remove that imageview from the view
[splashImage removeFromSuperview];
}];
return YES;
}
What I want is to do this using a storyboard, so I changed the code as below.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MyBookViewController *myNew = [[MyBookViewController alloc] init];
self.myBookViewController = myNew;
self.window.rootViewController = self.myBookViewController;
[self.window makeKeyAndVisible];
However I don't see my viewcontroller (MyBookViewController). I only see the image moving from right to left, then a black screen.
Any idea what is going wrong?
I just did it myself with help of this SO question.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle: nil];
MyBook001ViewController *controller = (MyBook001ViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"firstStory"];
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];
i think it is because of you are allocating new MyBookViewController. instead it you have to give reference of storyboard, on which you have your UI design for MyBookViewController, like this
MyBookViewController *myNew=[self.storyboard instantiateViewControllerWithIdentifier:#"MyBookViewController"];
be sure for ViewController identifier
UPdate1:
try with
MyBookViewController *myNew=[self.window.rootViewController];

Adding Label on Application Window from app delegate

I am using Xcode 4.5 and iOS 6.0, I have selected the default single view template from the xcode, I just want to add the label on the application window but I am unable to do so. Please correct me.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
label =[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 20)];
label.text = #"Test";
[label setBackgroundColor:[UIColor whiteColor]];
[self.window addSubview:label];
[self.window bringSubviewToFront:label];
[self.window makeKeyAndVisible];
return YES;
}
PS - I want my label on top of my ViewController view i.e. on the window so it will be always there despite changes in the views presented by window. I dont want to only show the label here.
I got the answer
[self.window.rootViewController.view addSubview:label];
Thanks all for giving the pointers.
Just Remove the RootviewController.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
label =[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 20)];
label.text = #"Test";
[label setBackgroundColor:[UIColor whiteColor]];
[self.window addSubview:label];
[self.window bringSubviewToFront:label];
[self.window makeKeyAndVisible];
return YES;
}
if you dont want to only show the label here then use like below.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.Viewcontroller.view addSubview:label];
Add the label to self.window.rootViewController.view instead of self.window
UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 20)];
label.text = #"Test"; [label setBackgroundColor:[UIColor whiteColor]];
[self.window.rootViewController.view addSubview:label];

How to present a (no nib) ViewController

I've created a ViewController (without nib files), so how do I load this viewController in the app delegtate? my current code is:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
viewController = [[MyCustomViewController alloc] init...]; // I use a custom init method
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
And how can I use the presentModalViewController method to show new view controllers of the same "CustomViewController" class?
THANKS for the help!
NOTE: By the way, I do see that this code does call my initialization method, and my ViewDidLoad method in my customViewController is being called however the screen is still black....
It looks like your properties are not set up correctly.
Check this line:
viewController = [[MyCustomViewController alloc] init...]; // I use a custom init method
self.window.rootViewController = self.viewController;
check that self.viewController is okay, and there's nothing stopping you from just doing:
self.window.rootViewController = viewController;
Whoops, I was just missing this code in my viewDidLoad Method:
self.view.frame = CGRectMake(0, 0, 320, 480);
self.view.backgroundColor = [UIColor whiteColor];
So everything was working, but the screen by default is black and without a frame.
I had to do just that in one of the apps I'm working on. Try typecasting your view controller
CDViewController *viewController = (CDViewController*)self.window.rootViewController;
viewController.managedObjectContext = self.managedObjectContext;
viewController.managedObjectModel = self.managedObjectModel;
// Override point for customization after application launch.
return YES;

App crash with "Unable to restore previously selected frame" message

I can't figure out why that code leads to app crash.
AppDelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.rootViewController = [[[RootViewController alloc]init]autorelease];
[self.window setRootViewController:self.rootViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Here is RootViewController.m code
-(void)loadView
{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 10, 10)];
[view setBackgroundColor:[UIColor lightGrayColor]];
[self.view addSubview:view];
[view release];
}
I get that message in the debugger
Unable to restore previously selected frame.
loadView is supposed to set the view. It is called when self.view is nil. Now you're calling [self.view addSubview:view]; UIKit calls loadView, and that creates an infinite recursion. You're supposed to do self.view = view; here.
loadView is responsible to set the view first. you missed to do that. Instead you added a view to self.view.
Change the code by below line:
self.view = view;
instead of [self.view addSubview:view];
Also it is advisable to call [super loadView] before returning from the function.