ipad: keybord at wrong position - xcode

When I have switched to another view (After returning from taking a picture or after switching to a view to select stuff in table) the ipad keyboard appears at the wrong position.
When I select a text field, I see this on my Ipad and on the simulator. (can't post images yet). If I turn my ipad (so that it aligns horizontal) and rotate back the keyboard is back normal.
https://devforums.apple.com/servlet/JiveServlet/showImage/2-701040-19966/Screen+Shot+2012-07-20+at+16.36.20.png
My code to switch to the camera for taking a picture...
- (IBAction)getCameraPicture:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.title = #"CameraPicture";
[self presentModalViewController:picker animated:YES];
}
My code to switch to a view with a table in it :
[self presentModalViewController:viewControllerSpanoTechProducts animated:YES];
code for returning after selecting stuff :
[self dismissModalViewControllerAnimated:YES];
how my app works: you have a main screen with buttons and textfield to fill in a form. when you push a button to select a product I switch to another viewcontroller with a table where you can select a product and a button 'done'. If you click the 'done' button I switch back to the original view.. hope this helps?
I'm just started with iOS.. Any help is appriciated!

At the time of switch user this code:
[yourTextFieldObject resignFirstResponder];
This might work.

Related

iOS presentViewController breaks autolayout

I have a TableView on top of a ViewController.
When I tap a row, I load a PDF Reader using:
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.delegate = self; // Set the ReaderViewController delegate to self
readerViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:readerViewController animated:YES completion:nil];
But when I come back, my layout seems to be broken:
I have tried solutions like:
Frame doesn't reflect auto layout constraints after dismissing modal view controller
iOS AutoLayout issue with ScrollView
But I can't still solve my issue. What do you recommend? Thanks

Presenting UIImagePickerController over modally presented view controller does not work correctly in iOS 8

I have presented UIImagePickerController from modally presented view controller. After clicking the image I get a black image instead of the clicked picture
I did something Like this.
//From ViewController1 I presented view controller2 with
- (IBAction)buttontappedToPresentViewController2:(id)sender
{
ViewController2* controller2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
controller2.modalPresentationStyle = UIModalPresentationPageSheet;
[self controller2 animated:YES completion:nil];
}
//In ViewController2, I presented the UIIMagePickerController
- (IBAction)cameraButtonTapped:(id)sender
{
UIImagePickerController *cameraController = [[UIImagePickerController alloc] init];
cameraController.mediaTypes = #[(NSString *)kUTTypeImage,(NSString*)kUTTypeMovie];
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:cameraController animated:YES completion:NULL];
}
After clicking the image you will get black screen instead of the captured image with retake and use photo options. If you select "Use Photo" option you get the correct image in callback.
Note: If you do not set UIModalPresentationStyle for viewController2, the code works fine.
Any idea what is going wrong here.
EDIT: I have used XCODE 5.1 and my target deployment is iOS 7. I am running the app on iOS8 device.

Show Whole Leaderboard when going to Leaderboard

I am wondering if i can show all leaderboards instead of going to a specific leaderboard in gamecenter. I have my game now that whenever you hit the leaderboard button it goes to my default, but I was wondering if there was a way to show all on the button click.
To view all of the leaderboards use this:
- (void) presentLeaderboards
{
GKGameCenterViewController* gameCenterController = [[GKGameCenterViewController alloc] init];
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
gameCenterController.gameCenterDelegate = self;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
The key difference here is that in my code I have
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
while you would have
gameCenterController.viewState = GKGameCenterViewControllerStateDefault;

UIImagePickerController within existing UIPopoverController resizing issue on iPad

I am working on an iPad app where I have a button that generates a popover controller that I am populating with a specific view controller. Here is the button code that generates the UIPopoverController and loads it with a specific view (signUpListAddEditViewController):
-(void)addSignUpList:(id)sender {
signUpListAddEditViewController = [[SignUpListAddEditViewController alloc] init];
popover = [[UIPopoverController alloc] initWithContentViewController:signUpListAddEditViewController];
popover.popoverContentSize = signUpListAddEditViewController.view.frame.size;
[popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
signUpListAddEditViewController.popover = popover;
}
Inside SignUpListAddEditViewController.m, I have several fields and a tableview. One of the fields is a UIButton where I display an image and allow the user to load a new image using this button. Since I am already in a popover, I swap the content controller with the UIImagePickerController. So far, so good.
-(void)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[popover setPopoverContentSize:popupScreenSize animated:YES]; // popupScreenSize is a CGSIZE set to 500 x 900
[popover setContentViewController:imagePicker animated:YES];
}
The view is swapped out with the imagePicker with the size remaining the same as the original view and I can see the various picture galleries (Camera Roll, Photo Stream, etc). Here is where it gets strange. As soon as I pick one of the galleries, the view is replaced with a thumbnail view of the pictures in that gallery AND THEN the view resizes to a much narrower width. The images are distorted and nearly impossible to select one of them.
I have tried setting [popover setPopoverContentSize:CGSIZE animated:YES] prior to every access to the popover controller, with everything resizing properly EXCEPT the detailed image view? Any ideas where I can override the thumbnail image gallery view?
Here is the code for the didFinishPickingMediaWithInfo method where I again override the content size:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[thisList setThumbnailDataFromImage:image];
[popover setPopoverContentSize:popupScreenSize animated:YES];
[popover setContentViewController:self animated:YES];
listImageButton.imageView.image = image;
}

iPad: How to display a different screen depending on orientation (landscape / portrait)

I have an iPad application that can be used in all four view modes (portrait up/down and landscape left/right). But at a certain point I have a View that I only want to be seen in landscape mode. So I do the following in the UIViewController that will trigger the action to view the landscape-only view:
- (void) showProperty:(Property *) property {
if ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft || [self interfaceOrientation] == UIInterfaceOrientationLandscapeRight) {
PropertyViewController *propertyView = [[PropertyViewController alloc] initWithNibName:#"PropertyViewController" bundle:[NSBundle mainBundle]];
propertyView.property = property;
[self.navigationController pushViewController:propertyView animated:YES];
[propertyView release];
propertyView = nil;
}
else {
RotateDeviceViewController *rotateView = [[RotateDeviceViewController alloc] initWithNibName:#"TabRotate" bundle: [NSBundle mainBundle]];
rotateView.property = property;
[self.navigationController pushViewController:rotateView animated:YES];
[rotateView release];
rotateView = nil;
}
}
This works fine and thus shows either the desired screen (PropertyViewController) when the iPad is held in landscape mode, and if not it shows the RotateDeviceViewController which shows the user a message that he/she is supposed to rotate the device to correctly view the screen.
So when the user then rotates his/her device to landscape mode I want to show them the right view (PropertyViewController). And all of this kinda works!
The problem arises though in this RotateDeviceViewController.. There I have the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
[self showProperty];
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
- (void) showProperty {
PropertyViewController *propertyView = [[PropertyViewController alloc] initWithNibName:#"PropertyViewController" bundle:[NSBundle mainBundle]];
propertyView.property = property;
[self.navigationController pushViewController:propertyView animated:YES];
[propertyView release];
}
So as soon as I rotate the device (when viewing the RotateDeviceViewController) to landscape mode I show the user the PropertyViewController. This works... But when the PropertyViewController appears it shows my layout 90 degrees rotated. So basically it shows the content in portrait mode instead of using the landscape mode (which is actually the way you are holding the device)..
I hope this makes sense and someone can show me what's causing this.
Screenshots to make it more clear:
When device is held in portrait mode
After rotating the device
At this point
- (BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)interfaceOrientation
You are telling the view controller what orientations you support. The device has not actually rotated yet therefore the view controllers intefaceOrientation property will still be portrait so when it is pushed onto the stack it thinks the device is portrait.
pseudo code
shouldAutoRotate... // at this point self.interfaceOrientation == portrait
// you push your controller here so it loads when the property is
I'm not sure if this will work well but the earliest I can see you can push is in
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

Resources