UITextFieldDelegate works on iOS 8 but not iOS 7 - ios7

I have a UIViewController that has a UITextField in it, and conforms to the UITextFieldDelegate protocol. When I first built the app iOS 7 was the latest iOS and when I selected the text field, the keypad would appear, as expected.
Along comes iOS 8 and Xcode 6. Nothing changed in the code since I first wrote it, but now, curiously, when I select the text field on an iOS 8 device the keypad appears, but on an iOS 7 device it does not.
Why would this be? Any ideas?
Here is my code:
#import "BBFeatVC.h"
#interface BBFeatVC ()
#end
#implementation BBFeatVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.featTextField.delegate = self;
// Set label
self.featLabel.numberOfLines = 0;
// enhance keypad
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(cancelNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:#"Apply" style:UIBarButtonItemStyleDone target:self action:#selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
self.featTextField.inputAccessoryView = numberToolbar;
}
-(void)cancelNumberPad{
[self.featTextField resignFirstResponder];
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = self.featTextField.text;
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *num = [f numberFromString:numberFromTheKeyboard];
NSInteger newStat = [num integerValue];
[[NSUserDefaults standardUserDefaults] setInteger:newStat forKey:self.featStat];
[self.featTextField resignFirstResponder];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

A red herring if there ever was one. As it turns out this was a case of the iOS Simulator detecting the hardware keyboard and therefore not raising the simulated iPhone keypad. The reason I thought the delegate was working on iOS 8 and not iOS 7 is because my device runs iOS 8 and so I would test on the device when I tested that version of iOS, and I used the simulator when I needed to test iOS 7. Once I tested iOS 8 on the simulator I discovered my flawed assumption and it dawned on me the difference was not between iOS versions but between device and simulator. I corrected the problem by going into the Simulator, and then in the Hardware Menu, then Keyboard, then uncheck the "Connect Hardware Keyboard" option.
This frustrated me to no end. I hope someone benefits from my posting!

Related

UIImagePickerController camera freezes when flip and cancel a few times

Hello I'm working in an app with camera.
I can open and use the camera correctly. But I find a bug:
When I open the camera, flips camera, again flips camera and press cancel. Do it a few times ( 3 - 5 ) . Open again the camera and I have a black freeze screen for a few seconds and if you take a picture see the image but the screen continue in black. After a few seconds the camera appears again and you can continue with the normal behavior. But I cant find a solution to this.
I searched a lot in internet and find some answers but nothing solve my problem.
Here a similar problem but the solution didnt work for me:
Stackoverflow - UIImagePickerController Freezes when camera flips
Stackoverflow - UIImagePicker freezes
Stackoverflow - iOS 7 UIImagePicker preview black screen
Stackoverflow - iDevice camera shows black instead of preview
Also I use DejalBezelActivityView to create a spinner area with a label DejalBezelActivityView
Any idea?
I have my .h declaration:
#property (nonatomic, strong) UIImagePickerController* picker;
- (void) takePhoto: (id)vc;
- (void) selectPhoto: (id)vc;
And my .mm code:
#synthesize picker = _picker;
- (id) init{
self = [super init];
if (self){
self.picker = [[UIImagePickerController alloc] init];
}
return self;
}
- (void)takePhoto:(id)vc{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
[VC_Camera showAlert];
return;
}
[self init];
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
[[VC_Camera getMainWindow] presentViewController:self.picker animated:YES completion:NULL];
}
- (void)selectPhoto:(id)vc{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
[VC_Camera showAlert];
return;
}
[self init];
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[[VC_Camera getMainWindow] presentViewController:self.picker animated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
self.picker = picker;
DejalActivityView * _activityView = [DejalBezelActivityView activityViewForView:[[UIApplication sharedApplication] keyWindow] withLabel:#"Loading"];
[self performSelector:#selector(cancelAfterDelay:) withObject:#{#"DejalAV":_activityView} afterDelay:1.0];
}
- (void) cancelAfterDelay:(NSDictionary*) dict
{
DejalActivityView* _activityView = [dict objectForKey:#"DejalAV"];
[DejalBezelActivityView removeViewAnimated:YES];
[self.picker dismissViewControllerAnimated:YES completion:nil];
}
Thanks :D
[UPDATE]
I try to use the UIImagePickerController as a singleton:
-(UIImagePickerController *) imagePicker{
if(!_imagePicker){
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else{
_imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
}
}
return _imagePicker;
}
And the problem persist.
This is a very late response, but for those still wrestling with this issue: I've noticed this seems to happen when something is either backing up the main thread, or affecting the graphics context on a separate thread. Those might be places to start looking.

How to set the Camera screen size in Retina 4?

I've made the simple camera app in iPhone. In iPhone 4, it works well with the proper camera screen size, but in iPhone5 it appear the black bar between the camera screen and the bottom bar.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:#"tick"
ofType:#"aiff"]],
&_tickSound);
self.imgPickController = [[[UIImagePickerController alloc] init] autorelease];
self.imgPickController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPickController.delegate = self;
self.imgPickController.showsCameraControls = NO;
posCaptDevice = UIImagePickerControllerCameraDeviceRear;
nCountSec = 0;
self.view.frame = [UIScreen mainScreen].bounds;
[self initCamera];
}
return self;
}
is your app iPhone 5 optimised?.It could be a reason. if your app is not iPhone 5 optimised,
This will help to do it
anyway you will have to do it. Now apps are not allowed to submit without iPhone 5 support .

Bugged Game Center Matchmaker appearance

I am developing multiplayer for my game and I have encountered following issue
I am using Cocos 2d 2.1 , iOS 6 and following code to show matchmaker (Landscape orientation)
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[GCHelper sharedInstance] findMatchWithMinPlayers:2 maxPlayers:4 viewController:[app navController] delegate:self];
And thats how it appears
Following code is used for that function
- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers
viewController:(UIViewController *)viewController
delegate:(id<GCHelperDelegate>)theDelegate {
if (!gameCenterAvailable) return;
matchStarted = NO;
self.match = nil;
self.presentingViewController = viewController;
delegate = theDelegate;
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
GKMatchmakerViewController *mmvc =
[[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
}
is this code in HelloWorldLayer? if so is that the first layer that the director calls? I have the same problem but it's fixes if I follow strictly the cocos2d template that was created for me. Meaning that I use the IntroLayer as the initial layer and from there it transitions into the HelloWorldLayer where I have the game center code. I think it has something to do with the director being loaded too late but I'm not sure
This happens when you try to push on a UIViewController, but you only have a UIView in your app, and no UIViewController. Let me guess, you do not have a rootViewController.
If you are working from the EAGLView template, you must declare a UIViewController for the UIView. This can be as simple as,
- (void) applicationDidFinishLaunching:(UIApplication *)application
{
window.rootViewController = [[UIViewController alloc] init];
window.rootViewController.view = glView; // MUST SET THIS UP,
// NOW THE EAGLView HAS A UIViewController.
[glView startAnimation];
}
Then, anytime you want to push on one of those GameKit UIViewControllers, use the presentViewController method of your Window object's rootViewController
For example:
[self.window.rootViewController presentViewController:vc animated:TRUE completion:^(void){puts("DONE");} ] ;
The bugginess will go away and the window will be correctly formed.

UITabBarItem finishedImageSelected placed offsetting the tab bar

I'm trying to customize UITabBarItem but I'm having problems with the image's position.
The image size is 81px x 49px, the same height as the UITabBar. This is how I set the image:
// AppDelegate
BlocosController *blocos = [[[BlocosController alloc] initWithManagedObjectContext:moc] autorelease];
UINavigationController *navBlocos = [[[UINavigationController alloc] initWithRootViewController:blocos] autorelease];
tabBarController = [[UITabBarController alloc] initWithManagedObjectContext:moc];
tabBarController.viewControllers = [NSArray arrayWithObjects: navData, navBlocos, navBairro, navAtualizar, nil];
// ...
// BlocosController.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:TITLE image:nil tag:10] autorelease];
[[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:#"tab_bar_blocos_selected"] withFinishedUnselectedImage:[UIImage imageNamed:#"tab_bar_blocos_unselected"]];
}
return self;
}
I've search on google and found this tutorial, the code uses the same API as I use and works as expected. The code in this article behaves just like mine, but since their background is the same color there's a illusion of it been correctly placed.
Why is the finishedImageSelected and the unselected are placed unaligned with the tab tab? How to fix it?
I've found the correct way to accomplish this and made a post: felipecypriano.com/2012/02/27/….
Basically the problem is that finishedImage is the icon not the icon and the background, it's possible to use with the background by adjusting the imageInset property.

UIImage Causing Views All Throughout the iPhone to Turn Black

Alright, this problem is rather bizarre, and I'm 99% positive at this point it's not a retain/release error. Basically I'm using UIImagePickerController to grab an image from either the library or the camera, but the resulting image causes some... strange things to happen. Though it's laggy to pull the image up in a detail view controller containing a UIImageView, the real problem is that if I repetitively pull up the view controller and dismiss it, eventually parts of the image will have disappeared!!! More disturbingly, if I attempt to pull it up again after this has happened, the whole image will have turned black, and other UIViews throughout both my App AND the iPhone itself will either flicker wildly or have turned black!!!! For example, both the iPhone wallpaper and the initial "slide to unlock" panel turn black and flicker, respectively... It makes no difference whether the photo came from the library or the camera. The problem is entirely averted (no lag, no blackness) if I do something like this:
//UIImage* image = (UIImage*)[info objectForKey:UIImagePickerControllerOriginalImage];
UIImage* image = [[UIImage alloc] initWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString:
#"http://wild-facts.com/wp-content/uploads/2010/07/Diving_emperor_penguin.jpg"]]];
Thus I can't imagine the problem having to do with anything other than the UIImagePickerController. Note that I'm still creating and dismissing it-- I'm just not grabbing the image out of it.
At first I thought the image was simply being overreleased, and the disappearing black chunks were parts of memory being overwritten. However, changing the image's retain count makes no difference. Then I thought, maybe the image is too large and somehow not getting properly released when I dismiss the UIImageView! Yet downloading a several MB image from the internet will not replicate the error. Then I thought, maybe the UIImagePickerController is disposing of the image, regardless of retain count! But copying the image failed as well. Furthermore, how could any of these things effect views that exist as deep as the iOS level?! I've researched, experimented, and Googled and no one has encountered this problem except for me... yet I'm not doing particularly strange! Is this an Apple issue? Did I forget something obvious? I've scanned up and down the documentation and guides to no avail, but perhaps I missed something.
None of this has worked:
Incrementing the retain count
Using [image copy]
None of this has replicated the problem with the downloaded image:
Decrementing the retain count
Downloading an image of size greater than 1 MB with large dimensions
I'm using the latest Verizon iPhone with iOS 4.2.8 (base SDK "overriden" to 4.3, whatever that means). 4.2.8 is the latest possible one for Verizon, though 4.3 is available for iPhones using AT&T.
Here's the code in glorious detail. I'm not yet checking for device compatibility, but it shouldn't matter concerning this. Perhaps I forgot some setting with the UIImagePickerController?
Quick Overview: I display an action sheet, then based on the user's input, display the image picker. I save the image as a transformable attribute on a Core Data object (delivery) using a custom transformer. I later hand the image to a detail view controller to display to the user.
IGDeliveryVC.m (parts of it, anyways. It's a tableview displaying the delivery's added media)
- (void)refresh
{
[mediaDisplayArray release];
NSSortDescriptor* sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:#"displayIndex" ascending:YES];
mediaDisplayArray = [[NSMutableArray alloc] initWithArray:
[delivery.deliveryMedia sortedArrayUsingDescriptors:
[NSArray arrayWithObject:sortDescriptor]]];
if (mediaDisplayArray == nil)
mediaDisplayArray = [[NSMutableArray alloc] init];
[self.tableView reloadData];
}
- (void)onAddMedia:(id)sender
{
#if TARGET_IPHONE_SIMULATOR
UIImage* image = [[UIImage alloc] initWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString:
#"http://wild-facts.com/wp-content/uploads/2010/07/Diving_emperor_penguin.jpg"]]];
[delivery addImage:image];
[self refresh];
[image release];
return;
#endif
UIActionSheet *options = [[UIActionSheet alloc] initWithTitle:#"Add Media from..."
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Camera", #"Library", nil];
[options showFromToolbar:self.navigationController.toolbar];
[options release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != 0 && buttonIndex != 1)
return;
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.mediaTypes = [NSArray arrayWithObjects:#"public.image",#"public.movie", nil];
switch (buttonIndex)
{
case 0:
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
break;
case 1:
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
}
[self presentModalViewController:picker animated:YES];
}
- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = (NSString*)[info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.image"])
{
UIImage* image = (UIImage*)[info objectForKey:UIImagePickerControllerOriginalImage];
//UIImage* image = [[UIImage alloc] initWithData:
// [NSData dataWithContentsOfURL:
// [NSURL URLWithString:
// #"http://wild-facts.com/wp-content/uploads/2010/07/Diving_emperor_penguin.jpg"]]];
[delivery addImage:image];
}
else if ([mediaType isEqualToString:#"public.movie"])
{
NSString* videoURL = (NSString*)[info objectForKey:UIImagePickerControllerMediaURL];
[delivery addVideo:videoURL];
}
else
{
NSLog(#"Error: imagePickerController returned with unexpected type %#", mediaType);
}
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
IGMedia* media = [mediaDisplayArray objectAtIndex:indexPath.row];
UIViewController* detailViewController =
[media isMemberOfClass:[IGMediaImage class]]
? [[IGMediaImageDetailVC alloc] initWithImage:((IGMediaImage*)media).image]
: nil;
if (detailViewController != nil)
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
IGMediaImageDetailVC.h (I use a xib :P )
#import <UIKit/UIKit.h>
#interface IGMediaImageDetailVC : UIViewController {
}
#property (nonatomic, retain) UIImage* image;
#property (nonatomic, retain) IBOutlet UIImageView* imageView;
- (id)initWithImage:(UIImage*)anImage;
#end
IGMediaImageDetailVC.m
#import "IGMediaImageDetailVC.h"
#implementation IGMediaImageDetailVC
#synthesize image;
#synthesize imageView;
- (id)initWithImage:(UIImage*)anImage
{
self = [super initWithNibName:#"IGMediaImageDetailVC" bundle:nil];
if (self)
{
self.image = anImage;
}
return self;
}
- (void)dealloc
{
[image release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView.image = self.image;
}
- (void)viewDidUnload
{
[super viewDidUnload];
[imageView release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
If there's anything I can do to make this post more legible, please let me know. I'll add things that don't work/replicate the problem to the appropriate list. Thanks for taking the time to read this!
I just figured out the problem, had to do with excessive memory use. Thanks goes to this amazing post: https://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more Basically, before ever displaying the image, I divide each dimension by 4, resulting in a total 1/16th of the memory I was using before. Here's the method I used (as per the awesome post):
+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
In the method call, I pass in CGSizeMake(image.size.width/4, image.size.height/4)
Hope this was helpful!