change view (storyboard) after zbar didFinishPickingMediaWithInfo inside a tab - ios

I'm still new to programming on the iPhone, and have researched my problem, but have no luck with any of the solutions.
I have managed to follow ZBar SDK Integration tutorial to have a working app at the end, inside a tab controller.
What I am trying to do is, move the results to a separate ViewController.
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
ProductViewController *product = [self.storyboard instantiateViewControllerWithIdentifier: #"ProductView"];
product.resultImage = [info objectForKey: UIImagePickerControllerOriginalImage];
product.resultText = symbol.data;
[reader dismissModalViewControllerAnimated:YES];
[self presentModalViewController:product animated:YES];
}
The problem I'm having with the code is that product view controller never displayed.
Using Xcode 4.5, iOS 6 SDK.

did you try
UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"ProductView"];
[reader presentViewController:newTopViewController animated:YES completion:nil];

I ended up abandoning the above approach and instead added function on my navigigation controller to handle displaying.
Displaying Scan:
[[self targetController] displayNewObject:scan];
On the receiving end:
- (void)displayNewObject:(_Scan *)scan
{
self.scan = scan;
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
[[self navigationController] popToRootViewControllerAnimated:NO];
[self performSegueWithIdentifier: #"ShowScanDetail" sender: self];
self.scan = nil;
}

Related

UIDocumentInteractionControllerDelegate check when document is loaded

Which delegate function of UIDocumentInteractionControllerDelegate is called when document is completely loaded on the preview?
Just to share, I have already tried :
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
And this is called when we close the preview.
This is a bit of a work around as there doesn't appear to be a completion handler for this in the documentation, as far as I can tell.
-(void)presentDocument:(NSURL*)url{
UIDocumentInteractionController *docInteration = [UIDocumentInteractionController interactionControllerWithURL:url];
docInteration.UTI = #"com.adobe.pdf";
docInteration.delegate = self;
[docInteration presentPreviewAnimated:YES];
}
-(void)documentInteractionControllerDidEndPreview: (UIDocumentInteractionController *)controller{
[self.navigationController dismissViewControllerAnimated:NO completion:nil];
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
UIViewController * vc = [[UIViewController alloc]init];
[self.navigationController presentViewController:vc
animated:YES
completion:^{
//This is ran once the document animation has completed
}];
return vc;
}
Hope this helps.
Luke

Segue between view controllers not functioning

I have an app that allows the user to take a picture, and when the picture is taken (push action) should then navigate to another view controller to allow the user to discard, edit, or save the photo. I try to segue from the camera view controller in the didFinishPickingMediaWithInfo method, like so:
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
UIImage *originalImage, *editedImage, *imageToSave;
// Handle a still image capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {
editedImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
if (editedImage) {
imageToSave = editedImage;
} else {
imageToSave = originalImage;
}
// Save the new image to camera roll (will change later)
UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil);
[self.capturedImages addObject: imageToSave];
_imageView.image = [self imageToSave:imageToSave];
}
CaptureViewController *capture = [[CaptureViewController alloc] init];
[self performSegueWithIdentifier:#"takePic" sender:self];
}
The didFinishPickingMediaWithInfo method is called when a button is pressed, prompting [_picker takePicture]; Here is my prepare for segue method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller
//this is just a temporary fix
if ([segue.identifier isEqualToString:#"takePic"]) {
CaptureViewController *destViewController = segue.destinationViewController;
}
}
The segue identifier is "takePic", so that's not the issue. That would be too simple. When I try to perform the segue, nothing happens. The camera still shows and the two buttons I have in the imagePickerController's cameraOverlayView are still there (although they are non-functional). Help is much appreciated!
I don't see where you're dismissing the image picker controller. UIImagePickerController is pretty picky about how you present it. So, make sure that you're presenting it the way it expects to be presented. When the image is captured or selected, you also need to dismiss the image picker controller. Since you don't see it going away, I strongly suspect that you're not dismissing it anywhere.
Add a line like:
[picker dismissViewControllerAnimated:YES completion:nil];
to your ... didFinishPickingMediaWithInfo: method.

Main app stop responding to events after UIViewController ends

i'm simply trying to show the camera or photo library so the user can select an image and return to the app. I could finally do it, but the problem that i'm facing, is that when the UIViewController ends (why the user selected an image or why the user pressed cancel) the app works, but events stopped working.
my UIViewController is defined like this:
#interface IOSNativeCb : UIViewController
- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info;
#end
#implementation IOSNativeCb
- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[picker release];
//log all the dictionary of the selected image
for (id key in info) {
NSLog(#"key: %#, value: %# \n", key, [info objectForKey:key]);
}
}
//if user canceled
- (void)imagePickerControllerDidCancelUIImagePickerController *)picker {
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[picker dismissViewControllerAnimated:YES completion:^{[self dismissViewControllerAnimated:YES completion:nil];}];
[self removeFromParentViewController];
[window makeKeyAndVisible];
}
#end
and i'm initializing with this from openfl:
const void initAppGallery(){
UIWindow *window = [UIApplication sharedApplication].keyWindow;
IOSNativeCb *wn = [[IOSNativeCb alloc] init];
[window addSubview: wn.view];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = wn;
[wn presentModalViewController:picker animated:YES];
[picker release];
}
tried several things in how i remove or dismiss the UIViewController to see if maybe the view still was principal and for that reason the events didn't worked anymore, but nothing so far.
any ideas of what i could try? anyone had any problem like this? is my first time coding in objetive-c + haxe, so i'm a bit lost of what functions or things could be the problem. i'm coding blind in a language i barely know.
Regards.
Some things that could help you find the error:
Use window.rootViewController = wn instead of [window addSubview:wn.view]
Don't release the picker after calling [picker dismissModalViewControllerAnimated:YES]. You already released the picker once on the initAppGallery method, so releasing it again could lead to unknown problems (probably crashes)
Calling [window makeKeyAndVisible] should be done at the end of initAppGallery.
Take also a look to this question, it might help you a bit.
the solution was more simple, i just added after [self removeFromParentViewController];:
[self.view removeFromSuperview];
and worked :D

Xcode5 error : Warning attempt to present <View> on <OtherView> while presentation is in progress

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];
}];
}

Simple view controller switch causes: Attempt to present while a presentation is in progress

I am learning how to handle view controller hierarchies using the storyboard. I have 2 ViewControllers: the root of type cwViewController (what I understand is 'self' below) and a second of type WorkspaceViewController. I am getting "Attempt to present while a presentation is in progress!" as a result of this code.
- (IBAction)nextView {
WorkspaceViewController *workspace = [[WorkspaceViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:workspace animated:YES completion:NULL]; }
The answer to How to present view controller properly? is the closest answer that could apply but doesn't quite fit this scenario because I'm not switching back and forth between VCs, I'm just presenting one, then dismissing it to display the original.
Then, I tried dismissing the current one before presenting the second, as some answers suggested, like this:
[self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController:workspace animated:YES completion:NULL];
But that just gets me an additional Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!
Doing some other research I saw similar problems were solved by adding a block to
[self dismissViewControllerAnimated:YES...]
But that doesn't help here because my warning occurs before I even get to a point where I call that dismiss method. Any further knowledge on how the order and hierarchy of views are meant to be handled would be a big help. Thanks very much.
Did you create a segue from the button to your WorkSpaceViewController? If so, you are likely attempting to present the WorkSpaceView twice - once when the button is selected and once from cwViewController. To eliminate the error, delete the segue from the button to WorkSpaceViewController and then recreate the segue - this time between cwViewController and the WorkSpaceViewController. That should take care of it.
- (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];
}];
}
try
[self presentModalViewController:workspace animated:YES];
if (![[self modalViewController] isBeingPresented]) {
[self dismissModalViewControllerAnimated:YES];
}

Resources