I have the following code where I am trying to show a PDF preview. It words perfectly on an iPad however when I am trying to do it on a iPhone it dosnt work.
QLPreviewController* preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:preview animated:YES completion:nil];
}];
The thread on the iPhone never makes it to this line
[self presentViewController:preview animated:YES completion:nil];
but works fine on ipad.. I am not sure what to even look at. Any help would be appreaciated.
To access the instances/variables (that are declared outside of the block) inside a block, you need to declare those instances/variables like this:
__block type identifier = initial value (optional) e.g, in your case use
__block QLPreviewController* preview = [[QLPreviewController alloc] init];
Try to use
[self.presentingViewController presentViewController:preview animated:YES completion:nil];
instead of
[self presentViewController:preview animated:YES completion:nil];
Related
I used UIImagePickerController to captrue photo from Camera. It used to work, but with iOS8 i am facing crash. Below is the code and crash log.
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
[self.navigationController presentViewController:imagePicker animated:YES completion:nil];
- (void)imagePickerControllerDidCancel:(UIImagePickerController *) Picker {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
Logs:
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
-[UIImagePickerController respondsToSelector:]: message sent to deallocated instance
Steps to reproduce the issue is,
1. Click on Camera button in App.
2. Camera opened.
3. Click on Cancel on Camera UI.
4. Click on Camera button again and the App is crashing now.
you should use
[self presentViewController:imagePicker animated:YES completion:nil];
and [self dismissViewControllerAnimated:YES completion:nil];
I was facing the same issue. I resolved it by passing "NO" in animation parameter in both these methods:
[self presentViewController:imagePickerController animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
I am still a noob when it comes to making applications for iOS and I don't understand why I am getting a certain error. For my current project I am trying to switch views but I cannot get it to work and I do not really understand why. I followed this tutorial for the button(http://www.youtube.com/watch?v=ph3XhJD8QAI) and although the tutorial is older, it still works. I had to edit some of the code to make sure that it worked for Xcode 5 though. Every time I press the button to switch the views I get an error that reads "Warning: Attempt to present < SecondView: 0xc918d50 > on < SeriouslyFunnyView: 0xc91a130 > while a presentation is in progress!" and the screen in the iPhone Simulator just goes black. I am also using Storyboard, i'm not sure if that is relevant to the situation or not. Can anyone possibly tell me what I am doing wrong ? Let me know if I need to add more code for clarification ! Thanks in advance for the help
Here is my code for the button that switches views
-(IBAction)SwitchView:(id)sender {
SecondView *second = [[SecondView alloc] initWithNibName:nil bundle:nil];
[self presentViewController:second animated:YES completion:NULL];
}
You must dismiss completely a view before present another. Try with:
[self dismissViewControllerAnimated:YES completion: ^{
SecondView *second =
[[SecondView alloc] initWithStyle:UITableViewStylePlain];
controller.modalTransitionStyle = UITableViewStylePlain;
[self presentViewController:second animated:YES completion:nil];
}];
comment the body of switchview, and check whether any controller is presented on click of switchview.. that looks silly but may be it'd b helpful to find out which controller is in progress... i'm also not used to storyboards ,, so .. hope that helps
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// TODO: make this all threaded?
// crop the image to the bounds provided
img = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(#"orig image size: %#", [[NSValue valueWithCGSize:img.size] description]);
// save the image, only if it's a newly taken image:
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
// self.image_View.image = img;
// self.image_View.contentMode = UIViewContentModeScaleAspectFit;
NSLog(#"Picker has returned");
[self dismissViewControllerAnimated:YES
completion:^{
ModalViewController *sampleView = [[ModalViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}];
}
This worked in iOS6, so not sure what the issue is.
inside my UINavigationController (ioNavController) I present the UIImagePickerController with the Following:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.modalInPopover = YES;
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:imagePicker animated:NO completion:^{ }];
in my UIImagePickerControllerDelegate (which does get called)I have the Following:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
//This does not work
[ioNavController dismissViewControllerAnimated:YES completion:^{ /* Cleanup if Needed */ }];
//This does not work
[[picker parentViewController] dismissViewControllerAnimated:YES completion:^{ /* Cleanup if Needed */ }];
//This does not work
[picker removeFromParentViewController];
// This presents a new view on the Nav Controller. It shows the new view ontop of the ImagePicker. Image Picker View does not repond to touches.
[ioNavController pageToSelect:0];
}
Your delegate it's in the same controller that called the imagepicker? The same controller that called presentViewController should call the line below, and the imagepicker will be removed correctly.
[self dismissViewControllerAnimated:YES completion:nil]; //self here it's the same reference that called presentViewController
let me know if worked or helped.
The UIImagePickerController will remove itself when you use this code:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)pPicker {
[pPicker dismissViewControllerAnimated:YES completition:NULL]; }
MainMenuViewController presents BonusViewController modally. I want to Dismiss BonusViewController then display a new BonusViewController, effectively "resetting" BonusViewController.
Im using notifications to call this method in MainMenuViewController
-(void)resetBonus{
[self dismissViewControllerAnimated:YES completion:nil];
[self presentViewController: BonusViewController animated:NO completion:nil];
}
I expected BonusViewController to be auto-detected as I was typing it in the presentViewController call above but it was not and none of my viewControllers show up as I type which Im assuming means im doing this all wrong. Do I have to initialize the VC or allocate it before I can present it like this? Or can I even do this at all since im using storyboards?
I also tried this though I believe this method is deprecated
-(void)resetBonus{
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController: BonusViewController animated:NO ];
}
Did what Sumanth suggested but I get this message now:
so now I m doing :
#import "BonusViewController.h
....
-(void)resetBonus
{
BonusViewController *bonus = [[BonusViewController alloc]init];
[self dismissModalViewControllerAnimated:NO];
[self presentModalViewController: bonus animated:NO ];
}
the errors are all gone but when BonusViewController is presented the display is solid black, i can hear the sounds going but cant see anything on the screen
you should allocate and initialize the viewcontroller and present that using presentModalViewController write like this
BonusViewController *bonus = [[BonusViewController alloc]init];
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController: bonus animated:NO ];
Also dont forget to write #import "BonusViewController.h" in .h file
BonusViewController *objBonus = [[BonusViewController alloc]init];
[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:objBonus animated:YES completion:NULL];
You need to create and object of the viewcontroller and you are directly passing the viewcontroller which is not possible
#import "BonusViewController.h"
-(void)resetBonus
{
BonusViewController *BonusViewController = [[BonusViewController alloc]init];
[self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController: BonusViewController animated:NO completion:nil];
}
Set Both of animated is NO
EDIT : #import "BonusViewController.h"
Im sure the answers given were correct but I could not get them to work properly. For some reason BonusViewController seems to be displayed as I can hear the sounds going but the screen is black and nothing is displayed visually.
I ended up doing the below for now in the intrest of time but this isnt the smooth effect I was really going for.
I have to re-visit this when I have more time to figure out a better way to do it.
-(void)endBonus
{
[self dismissViewControllerAnimated:NO completion:^{
[self performSelector:#selector(resetBonus) withObject:nil afterDelay:1];
}];
}
-(void)resetBonus
{
[self performSegueWithIdentifier: #"segueToBonus" sender: self];
}
In iOS5 you could use this snippet to force the orientation:
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
However this causes an EXC_BAD_ACCESS in iOS6. How can a certain orientation be forced in iOS6?
Just to complete the previous answer, you should do this:
UIViewController *viewController = [[UIViewController alloc] init];
[self presentViewController:viewController animated:NO completion:^{
[viewController dismissModalViewControllerAnimated:NO];
}];
And iOS 6 is no longer under NDA.
In case anyone still cares about this, here's the iOS6 code snippet (I placed it in my viewDidLoad routine):
UIViewController *viewController = [[UIViewController alloc] init];
viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:viewController animated:NO completion:^{
[self dismissViewControllerAnimated:NO completion:nil];
}];
At first presentModalViewController and dismissModalViewControllerAnimated are deprecated and probably iOS6 will not use these methods correctly. You should use similar methods with complition block instead.
The second thing is that [self dismissModalViewControllerAnimated:NO]; tries to dismiss self firstly. Is this correct in your case?
And last thing iOS6 is under NDA