This code causes my app to crash on an iPhone 4 and on the simulator but works perfectly fine on a 3GS. Any ideas why this might be?
-(IBAction)startButtonClicked{
GameViewController *screen = [[GameViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
}
Have you checked out what's happening in screen's viewWillAppear and viewWillLoad methods? It looks like some issue in your init code there. Where are you opening a URL?
Related
I upgraded to x code 4.6 SDK 6.1 and now
[self.tabBarController presentViewController:loginViewController animated:YES completion:nil];
is Threading out.
This code worked with 6.0 on 6.0 and below simulators but now 6.0 and 6.1 crash while 5.1 and below simulators still run fine.
Basically in my app delecate i call a tab bar then run a login screen ontop of that till its dismissed.
EDIT: I am not using AutoLayout anywhere.
Got it I was under the impression that adding ~iPad/~iPhone to my xib name would work for a universial app in choosing which xib to use automatically. Well on the 5.1 simulators it does however on 6 and above it does not.
so here is the correct code.
LoginViewController *loginViewController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController_iPhone" bundle:nil];
viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPhone" bundle:nil];
loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginViewController~iPhone" bundle:nil];
} else {
viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController_iPad" bundle:nil];
viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPad" bundle:nil];
loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginViewController~iPad" bundle:nil];
}
I am using the RedLaser SDK. My app is a split view. I'm trying to launch a RedLaser overlay when a barbutton is pressed on the master view controller.
The method gets called when the button is pressed and that's where the problems start. I have 3 different versions of the code that launches the overlay. Each has it's own problem.
Option 1
This was my baseline and I knew it wouldn't work because I hadn't initialized the overlay. The following code launches the view controller correctly but (obviously) doesn't do what I want.
// Working Code that brings up dialog but doesn't start camera overlay
SRSScanVINViewController *scanVINViewController y= [[SRSScanVINViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:scanVINViewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:navController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Option 2
This code initiates the overlay controller and launches it without crashing. The overlay is working and the camera is active. The problem is that the viewcontroller/overlay is taking the whole screen. My controls (buttons, etc) are all layed out as if the view controller is taking a portion of the upper-left portion of the screen. This would work if I could get the overlay to be sized correctly.
// Working code that shows the overlay (camera on) but the overlay takes the whole screen
SRSScanVINViewController *scanVINViewController = [[SRSScanVINViewController alloc] init];
[pickerController setOverlay:scanVINViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:scanVINViewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:pickerController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Option 3
This attempt was to fix the problems in option 2 (above). Here is the code:
SRSScanVINViewController *scanVINViewController = [[SRSScanVINViewController alloc] init];
[pickerController setOverlay:scanVINViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pickerController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:pickerController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
It crashes with the following error (nslog):
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <SRSMasterViewController: 0x1f59f540>.'
*** First throw call stack:
(0x37ecb88f 0x331fc259 0x30d86441 0x7f6b5 0x7edf7 0x37e253fd 0x30cbfe07 0x30d855e7 0x37e253fd 0x30cbfe07 0x30cbfdc3 0x30cbfda1 0x30cbfb11 0x30cc0449 0x30cbe92b 0x30cbe319 0x30ca4695 0x30ca3f3b 0x3630522b 0x37e9f523 0x37e9f4c5 0x37e9e313 0x37e214a5 0x37e2136d 0x36304439 0x30cd2cd5 0x7deb5 0x7de50)
terminate called throwing an exception
Any help would be greatly appreciated. Thanks!
I got the code to work but still have a couple of issues. Here's the code:
SRSScanVINViewController *scanVINViewController = [[SRSScanVINViewController alloc] init];
[pickerController setOverlay:scanVINViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:scanVINViewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
pickerControllerPopover = [[UIPopoverController alloc] initWithContentViewController:pickerController];
[pickerControllerPopover setDelegate:self];
[pickerControllerPopover setPopoverContentSize:CGSizeMake(320.0f, 460.0f)];
[pickerControllerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}
else
{
[self presentViewController:pickerController animated:YES completion:nil];
}
This sets the size of the popover to the same size as my original controller (defined in the nib). I still have a couple of issues though.
The controller has 4 buttons in a button bar at the bottom. It also has a UIImage. The first time I load this controller, the buttons (and button bar and UIImage) are either missing are located in strange places. If I dismiss the popover controller by touching the screen somewhere outside of the controller and load the controller again, the controls are all in the right places. In fact, they are in the right places every time EXCEPT the first time.
Any ideas?
How can i display the background of the NavigationController (including title/buttons) in my UIPopovercontroller on the iPhone?
At the moment it looks like that:
In my PopoverView-ViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.hidden = NO;
self.navigationController.navigationBarHidden = NO;
self.navigationItem.title = #"self.navigationItem.title";
}
When calling Popover:
InfoView *iv = [[InfoView alloc] initWithNibName:#"InfoView" bundle:nil];
UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];
self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
[self.pop setDelegate:self];
[self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];
It should look like this:
At first UINavigationController doesn't have own background, it shows background of content view controller. If you can show popover with navigation controller successfully, then check your InfoView. Does it's view has some background?
Second, I tried to execute your code multiple times in different configurations on iPhone, but always have received error
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[UIPopoverController
initWithContentViewController:] called when not running under
UIUserInterfaceIdiomPad.
And that was not surprise for me. Even if you could make it work, then Apple may reject your application.
2.1 Apps that crash will be rejected - Just test your code on several devices and see result.
your code
InfoView *iv = [[InfoView alloc] initWithNibName:#"InfoView" bundle:nil];
UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];
self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
[self.pop setDelegate:self];
[self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];
is perfect just hide the default navigation controller and add a navigationBar in the XIB of InfoView.xib and write the cancelButtonAction there to perform the dismissal of the view or the detail of the tableview selection. It Works fine, Please check the image i have done the same way, and believe me it works fine.
Add this to your code before the line [self.pop presentPopoverFromBarButtonItem:se..:
uc.modalPresentationStyle = UIModalPresentationCurrentContext;
See the documentation for the modalPresentationStyle property.
I think you'll need to paste in more of the code for your InfoView controller, as I suspect that's where the problem is.
Have you tried setting up your background view as a class?
[pop setPopoverBackgroundViewClass:bgView];
I have an App that works great in 3.1.2, yet when I revert to 2.2.1 my method to flip the view doesn't work, using the following code:
-(IBAction)infoButtonPressed:(id)sender
{
SecondViewController *second = [[SecondViewController alloc] initWithNibName: nil bundle:nil];
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:second animated:YES];
}
I get the following error (http://screencast.com/t/YTJlYTgz). Thoughts on how I can fix this easily?
modalTransitionStyle is only available for 3.0+. If you want to have a similar transition you will have to create the animation transition yourself. Take a look at the following UIView function
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache
I'm still facing the problem when I launch my application in iPhone.
It shows the stack over flow by presentModelViewController because I'm using number of viewcontroller and calling the same viewcontroller from other viewcontroller but it gets terminated. Here I'm showing the code which I'm using in whole program to call other view controller
UV_AlarmAppDelegate *app7 = (UV_AlarmAppDelegate *)[[UIApplication sharedApplication]delegate];
[self presentModalViewController:app7.frmComparisionChartLink animated:YES];
[app7 release];
Still I'm releasing the pointer but still my app gets terminated.
You shouldn't release the app delegate. In short, unless you alloc, copy or retain an object you don't need to release it.
Apple's documentation shows modalPresentation done like this;
UIViewController *uiViewController = [[UIViewController alloc] initWithNibName:#"UIViewController" bundle:nil];
uiViewController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:uiViewController];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[uiViewController release];
Hopefully that helps.