objective C unable to switch views after scanning a QR code using ZBar - iphone

I am developping an App using XCode 4.2 that detects a QR code.
I am trying to make a switch view after QR code detection but it is not working at all
here is the code am using :
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
NSString *string=symbol.data;
NSString *string2=#"1234";
if ([string isEqualToString:string2]) {
//this is the part that is not working : it doesn t load the AboutView at all
AboutView *about = [[AboutView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:about animated:YES];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"This is not a recognized QR code!"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
}
thanks

The issue is that the reader is the presented view controller in zbar's example code
-(void)presentReaderInViewController:(UIViewController*)vc
and you are treating self as if it is presented
You should use reader to present your AboutView and only dismiss reader in the else block
if ([string isEqualToString:string2]) {
//this is the part that is not working : it doesn t load the AboutView at all
AboutView *about = [[AboutView alloc] initWithNibName:nil bundle:nil];
[reader presentModalViewController:about animated:YES];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"This is not a recognized QR code!"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
}
You might also want to wait to dismiss reader in the delegate method of your alert view (create a soft reference and dismiss that... myReader = reader; when you set up the alertview)
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
[myReader dismissModalViewControllerAnimated: YES];
}

Related

i want to take values from alert view (login id and password) and check if the values for transition using storybords

// when i click the button i want an alert view to appear and then entring the login details , if the details are correct then move to next view else not. how to do this ?
// now when i click on the button alert view appears when myButton method ends. how to control the flow ?
- (IBAction)myButton:(id)sender
{
flag= [self alertview];
if (flag)
{
SecondViewController *svc =[self.storyboard instantiateViewControllerWithIdentifier:#"vinay"];
[svc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:svc animated:YES completion:nil];
}
}
-(int)alertview
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Login"
message:[NSString stringWithFormat:#"Enter Login ID and Password:"]
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
flag=1;
[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
[alert show];
return flag;
}
What I have done to solve this is as below :
Need to conforms to the UIAlertViewDelegate protocol in your .h file
Then need to implement the delegate method for UIAlertView. Method is alertView:clickedButtonAtIndex:.
Then in method have to track down the button tapped using the button index and to access the text fields of alert view use NSString *pass = [alertView textFieldAtIndex:0].text; code. (Here the 0 is the first textbox)
Enjoy coding :)

Email Signature App Iphone

I am making an email signature application that allows user to make signatures and use them to send with emails, Their is signature name(Text Field), content(Text View) and image(Image View) and i am saving them in Database so that if the user selects the signature name from the table view that is on the second view the preview will show up on the same view like if i select signature 1 from table view then in preview section the signature image should show up with the signature content in (Text View), and then on the same view we press send(Button) the text and image from the Text View of preview section will be copied to clipboard and then in third view i can paste it in the message section and send the email, is it possible to do that if yes how can i implement it or any other idea how to do this ?
i have this one method for send email with image and message .. just add MFMessageComposeViewControllerDelegate in .h file and add framework MessageUI.framework in your project
-(void)sendMailWithImage:(NSString *)message Image:(UIImage *)image{
if ([MFMailComposeViewController canSendMail])
{
UIImage *tempImageSave=image;
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
NSString *mailBody = message;
NSData *imageData = UIImagePNGRepresentation(tempImageSave);
[mailComposeViewController addAttachmentData:imageData mimeType:#"image/png" fileName:#"Testing"];
[mailComposeViewController setMessageBody:mailBody isHTML:NO];
mailComposeViewController.mailComposeDelegate = self;
[self presentViewController:mailComposeViewController animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"e-Mail Sending Alert"
message:#"You can't send a mail"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
and this bellow method is delegate method of MFMessageComposeViewControllerDelegate
#pragma mark - MFMessage Delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
if (result == MFMailComposeResultSent)
{
NSLog(#"\n\n Email Sent");
}
[self dismissViewControllerAnimated:YES completion:nil];
}
i hope this help you...

Why does my camera interface act weird when I use UIImagePickerController?

In my app I want the user to be able to take a picture or use one from the photo library. When the user clicks the button I made a alert view pops up at the user can choose between taking a new photo or one from the photo library. Here is the code I've used:
- (void)PictureAlert:(id)sender {
UIAlertView *AlertDialog;
// Setting up AlertDialog.
AlertDialog = [[UIAlertView alloc] initWithTitle:nil
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Choose From Library", #"Take New Picture", nil];
[AlertDialog show]; }
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *ButtonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if ([ButtonTitle isEqualToString:#"Choose From Library"]) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
// Pick photo.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
} else if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
// Setting up AlertDialog.
UIAlertView *AlertDialog;
AlertDialog = [[UIAlertView alloc] initWithTitle:#"Error accessing photo library"
message:#"Device does not support a photo library"
delegate:self
cancelButtonTitle:#"Dismiss"
otherButtonTitles:nil];
[AlertDialog show];
}
} else if ([ButtonTitle isEqualToString:#"Take New Picture"]) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// Take new photo.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.wantsFullScreenLayout = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
} else if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// Setting up AlertDialog.
UIAlertView *AlertDialog;
AlertDialog = [[UIAlertView alloc] initWithTitle:#"Error accessing camera"
message:#"Device does not support a camera"
delegate:self
cancelButtonTitle:#"Dismiss"
otherButtonTitles:nil];
[AlertDialog show];
}
}
}
The problem is that if the user wants to take a new picture the camera interface pops up, and then if you rotate the device the interface looks like this:
And then when the user rotate it back it suddenly looks like this:
A little side problem is that the camera takes a long time to load.
Any thoughts would be appreciated :)
A few things you might want to consider:
Setting the wantsFullScreenLayout property to YES will cause the view to ignore the status bar. But since you are using the default camera controls, the status bar hides automatically. This is the most likely cause for the 20 pixel grey area on the bottom of the image.
The default camera controls are designed to be in portrait mode only. Since your first image looks like you somehow rotated the screen, you should look into your code (probably shouldAutoRotate) and see why you are rotating the view like that. This should fix the problem of the zoom you are getting in your landscape picture.
You will have memory leaks if you create a UIImagePickerController, present it, and then have no reference to it to release it later. I would recommend setting the UIImagePickerController in the interface, and setting it up in the viewDidLoad method. Try:
.h
#interface yourView:UIViewController <UIImagePickerControllerDelegate> {
UIImagePickerController * picker;
}
.m
- (void)dealloc; {
[picker release];
[super dealloc];
}
- (void)viewDidLoad; {
[super viewDidLoad];
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; {
NSString *ButtonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if([ButtonTitle isEqualToString:#"Choose From Library"]){
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
else{
// Setting up AlertDialog.
UIAlertView *AlertDialog;
AlertDialog = [[UIAlertView alloc] initWithTitle:#"Error accessing camera"
message:#"Device does not support a camera"
delegate:self
cancelButtonTitle:#"Dismiss"
otherButtonTitles:nil];
[AlertDialog show];
[AlertDialog release];
}
}
else if([ButtonTitle isEqualToString:#"Take New Picture"]){
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
else{
// Setting up AlertDialog.
UIAlertView *AlertDialog;
AlertDialog = [[UIAlertView alloc] initWithTitle:#"Error accessing camera"
message:#"Device does not support a camera"
delegate:self
cancelButtonTitle:#"Dismiss"
otherButtonTitles:nil];
[AlertDialog show];
[AlertDialog release];
}
}
}
This should clean-up the memory leaks, and improve the load time. Hope that Helps!
Some time its happened if you are using a old generation iphone that have current os for example you are having iphone 3G and you update its ios to ios5 then some of the app you installed can behave differently you can check your app to another device for rectify your problem.
Make sure you set the view controller hierarchy, with mainWindow.rootViewController and [vc addChildViewController:]. This propagates orientation information down to where you need it.
It looks like for my project this was happening because you have not written the shouldAutoRotateToInterface: method in your root view controller. The rotate message propagates all the way down to the root view controller's shouldAutoRotateToInterface delegate when UIImagePickerController is called. Your method should look like this:
- (BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
When I upgraded my project to iOS 5, I borrowed my root view controller from an iOS 3 project. iOS 3 did not automatically write this method in view controller classes Try it out and let me know.

IOS development, using UITabBarController and UIImagePickerController, How to go from one tab to another?

I can't seem to find an answer for this, or maybe can't understand the things people wrote over the web...
I have a UITabBar with 3 tubs.
One of the tabs is a UIImagePickerController. This TabBar Item is connected to a view controller that i set also as the delegate for the Image picker (camera).
I want that then someone take a photo or press cancel, The first TabBar item will be choosen (don't want to stay in the TabBar that holds the camera).
My question is, How do I "talk" with the TabBar controller from a view controller that is in one of the TabBar items?
my code in the TakePhotoViewController.m file that is in the 3rd TabBer item and i want to go the first item.
-(void) viewWillAppear:(BOOL)animated{
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imgPicker animated:YES];
}
and the delegate methods:
#pragma mark -
#pragma mark - UIImagePicker delegate methods
//saving the image that was taken
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
[picker release];
}
//alerting the user if the images was saved or not
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"Image saved to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
//if user is cancelling the camera
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}
Thank you very much,
Erez
[self.tabBarController setSelectedIndex:1];
You can pass your desired tab index value instead of 1.

IBActions are not working in another viewcontroller

i have created a project which has different xib viewcontrollers.In first view am selecting an image through picker controller and am displaying it in the secondviewcontroller.In secondview controller i have some buttons and i have given some IBActions to them.Here starts my problem that am successfully displaying the image in secondviewcontorller but when i tap on button in that viewcontroller app is terminating and the debugger showing the error message as program terminated due to uncaught exception
Here is the code:
To select the pic through pickercontroller in first view
-(IBAction)btnChoosePicClicked {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else
{
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:#"Error accessing photo library" message:#"Device does not support a photo library" delegate:nil cancelButtonTitle:#"Drat!" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
displaying in the second view and assigning the actions .h file
#interface editScreen : UIViewController{
IBOutlet UIButton *btnRotate;
IBOutlet UIButton *btnLibrary;
IBOutlet UIImageView *imgView;
int RotateAngle;
}
-(void)setImage:(UIImage *)img;
-(IBAction)btnLibraryClicked;
-(IBAction)RotateImage;
#end
.m file
#implementation editScreen
-(void)setImage:(UIImage *)img
{
[imgView setImage:img];
imgView.userInteractionEnabled = YES;
}
-(IBAction)RotateImage
{
CGAffineTransform transform = imgView.transform;
transform = CGAffineTransformRotate(transform, M_PI/2);
imgView.transform=transform;
RotateAngle+=90;
if(RotateAngle>=360)
{
RotateAngle-=360;
}
//imageview.transform = CGAffineTransformScale(imageview.transform, -1.0, 1.0);
}
-(IBAction)btnLibraryClicked {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
// NSFileHandle *fileHandle = [[NSFileHandle alloc]initWithFileDescript
}
else
{
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:#"Error accessing photo library" message:#"Device does not support a photo library" delegate:nil cancelButtonTitle:#"Drat!" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
I dont know whats wrong with my code please help me.I have given appropriate connections in IB..
Thanks in Advance
For some UIKit class, his delegate has some methods which must be implemented.
For example, UIImagePickerViewControllerDelegate must implement following methods:
– imagePickerController:didFinishPickingMediaWithInfo:
– imagePickerControllerDidCancel:
For your above codes, I don't know whether these methods are implemented or not. Hope these information can help you.