UISearchBar Custom InputView Crash in iOS8 - uitextfield

I have UISearchBar that with Custom InputView. Now i can't set Custom InputView for UISearchBar in iOS8. It's crashing.
Here is how i set Custom InputView for UISearchBar
for(int i =0; i<[[[self.sBar.subviews objectAtIndex:0] subviews] count]; i++) {
if([[[[self.sBar.subviews objectAtIndex:0] subviews] objectAtIndex:i] isKindOfClass:[UITextField class]])
{
[[[(UITextField*)[sBar.subviews objectAtIndex:0] subviews] objectAtIndex:i] setFont:[UIFont fontWithName:#"CustomFont" size:15]];
UITextField* search=[[(UITextField*)[sBar.subviews objectAtIndex:0]subviews] objectAtIndex:i];
search.delegate = self;
[[[(UITextField*)[self.sBar.subviews objectAtIndex:0] subviews] objectAtIndex:i] setInputView:MyKeyboard];
}
Here is crash Log.
Could not load the "" image referenced from a nib in the bundle with identifier "com.company.MyApp"
2014-09-23 13:34:13.816 MyApp[1651:61729] Could not load the "" image referenced from a nib in the bundle with identifier "com.company.MyApp"
It's working fine in iOS 7 But Now Crash in iOS8.
How can i fix it?

I got answers for my own question.
But you need to check iOS Version first for iOS8 because this code doesn't work perfectly for iOS7.
if([systemVersion isEqualToString:#"8"])
{
UITextField *search = (UITextField *)[[[self.sBar.subviews objectAtIndex:0] subviews] objectAtIndex:0];
[search setFont:[UIFont fontWithName:#"MyCustomFont" size:15]];
[search setInputView:self.customKeyboard];
[search setTextColor:[UIColor whiteColor]];
[self.customKeyboard setTextView:search];
[search reloadInputViews];
}

Related

Play Landscape Video in iOS8 with Landscape Correct Statusbar Inside Portrait App

Portrait App, loads video that displays in landscape.
in iOS7 all works fine (minor fix this is iOS6 too) but in iOS8 the statusbar, although showing in landscape actually shows at the size of a portrait statusbar so it only occupies the top left hand 60% of the video (if holding device in landscape).
The code I'm using is as follows:
- (void)viewDidLoad
{
[super viewDidLoad];
[planTitleLabel setText:[[ProgrammeHandler sharedHandler]
stringForElement:kPlanStringElementPlanTitle
onDay:0 inPlan:selectedPlan]];
}
- (NSUInteger)supportedInterfaceOrientations{
return 0;
}
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0) {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:FALSE];
[[UIApplication sharedApplication] setStatusBarHidden:TRUE withAnimation:UIStatusBarAnimationNone];
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0 && [[UIDevice currentDevice].systemVersion floatValue] < 9.0) {
[[UIApplication sharedApplication] setStatusBarHidden:TRUE];
}
NSString *moviePath = [[ProgrammeHandler sharedHandler] pathForAsset:kAssetVideoIntro onDay:0 forPlan:selectedPlan];
CGSize screenBounds = [[UIScreen mainScreen] bounds].size;
[whiteFadeView setFrame:CGRectMake(0, 0, screenBounds.width, screenBounds.height)];
NSURL *videoURL = [NSURL fileURLWithPath:moviePath];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[[moviePlayer view] setBackgroundColor:[UIColor blackColor]];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
//For viewing partially.....
moviePlayer.view.transform = CGAffineTransformMakeRotation(M_PI/2);
[moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[movieView setAlpha:0];
[moviePlayer.view setFrame:[movieView frame]];
moviePlayer.view.backgroundColor = [UIColor blackColor];
[movieView addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(hideControl)
name:MPMoviePlayerLoadStateDidChangeNotification
object:moviePlayer];
[UIView animateWithDuration:0.5f delay:0.50f
options:UIViewAnimationOptionCurveEaseIn
animations:^{[movieView setAlpha:1];} completion:^(BOOL fin){ }];
}
- (void) hideControl {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerNowPlayingMovieDidChangeNotification
object:moviePlayer];
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
}
I did see this question but don't think it applies in my case.
iphone: rotation in mpmovieplayercontroller?
Does any one know how to restore the statusbar to it's fullscreen 'width'?
Ok, after looking over this again today I noticed that there was an error that iOS7 seems happy with but it was correctly throwing an error in iOS8. For anyone else with the same issue:
The fix is simply to apply the transformation to the moviePlayer itself rather than the subview. e.g.
replace
moviePlayer.view.transform = CGAffineTransformMakeRotation(M_PI/2);
with
movieView.transform = CGAffineTransformMakeRotation(M_PI/2);

ALAssetsLibrary writeImageToSavedPhotosAlbum block the program in iOS8

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSMutableDictionary* meta = [[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
UIImage* img = [info objectForKey:UIImagePickerControllerOriginalImage];
if(self.locationManager.location){
NSDictionary* locationMeta = [self gpsDictionaryForLocation:self.locationManager.location];
[meta setObject:locationMeta forKey:(NSString*)kCGImagePropertyGPSDictionary];
}
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:img.CGImage metadata:meta completionBlock:^(NSURL* assetUrl, NSError* error){
//.......
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
This code worked fine in iOS7. After I upgraded my device to iOS8, the program was blocked and imagePickerView didn't dismiss.
Is this a bug in iOS8? Anyone can help me?

Does adding a subview to SDCAlertView work properly on iOS 8?

I had used an instance of SDCAlertView in my project to add a UITextView inside an alert to do some facebook posts.It doesnt seem to work properly anymore on ios8.
I had used the following code.
SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:#"Post To Facebook"
message:#""
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Post", nil];
UITextView *textView = [[UITextView alloc] init];
[textView setTranslatesAutoresizingMaskIntoConstraints:NO];
[textView setEditable:YES];
textView.autocorrectionType = UITextAutocorrectionTypeNo;
[alert.contentView addSubview:textView];
[textView sdc_pinWidthToWidthOfView:alert.contentView offset:-5];
[textView sdc_pinHeight:120];
[textView sdc_horizontallyCenterInSuperview];
[textView sdc_verticallyCenterInSuperviewWithOffset:SDCAutoLayoutStandardSiblingDistance];
[alert showWithDismissHandler: ^(NSInteger buttonIndex) {
NSLog(#"Tapped button: %#", #(buttonIndex));
if (buttonIndex == 1) {
NSLog(#"POST %#", textView.text);
}
else {
NSLog(#"Cancelled");
}
}];
Result on iOS 7
Result on iOS 8 GM
Please let me know if I can fix this issue with some change in my code.
I managed to fix this problem by replacing following line
[textView sdc_verticallyCenterInSuperviewWithOffset:SDCAutoLayoutStandardSiblingDistance];
with the following:
[alert.contentView sdc_pinHeight:120 + SDCAutoLayoutStandardSiblingDistance];
[textView sdc_alignEdgesWithSuperview:UIRectEdgeTop insets:UIEdgeInsetsMake(SDCAutoLayoutStandardSiblingDistance, 0, 0, 0)];
If anyone wants to refer more about this discussion, please visit the following link
https://github.com/sberrevoets/SDCAlertView/issues/49

xcode iOS6 orientation landscape

I see a lot of questions about this subject but am unable to find a solution to the problem I am experiencing. I have created an iPad app that should be Landscape only - it works fine when ran on any os prior to iOS6 but on iOS6 the app opens in portrait view. This screenshot shows what I mean (sorry not a great explanation) http://s1342.beta.photobucket.com/user/designedbyria/media/ScreenShot2012-11-02at122113.png.html
I'm guessing the problem is somewhere in the below code, but I can't be sure. I have set the supported Interface Orientations to Landscape Left and Landscape Right only - but this has not worked. I have also taken a look at the questions here with no luck..
I am using xcode and cordova/phonegap
Interface orientation in iOS 6.0
Set orientation to landscape mode in xcode 4.5 GM IOS 6
iOS 6 apps - how to deal with iPhone 5 screen size?
Thanks in Advance!
/**
* This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
/
- (BOOL) application:(UIApplication)application didFinishLaunchingWithOptions: (NSDictionary*)launchOptions {
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString* invokeString = nil;
if (url && [url isKindOfClass:[NSURL class]]) {
invokeString = [url absoluteString]; NSLog(#"iwill launchOptions = %#", url);
}
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.autoresizesSubviews = YES;
CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];
self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES;
self.viewController.wwwFolderName = #"www";
self.viewController.startPage = #"index.html";
self.viewController.invokeString = invokeString;
self.viewController.view.frame = viewBounds;
// check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation
BOOL forceStartupRotation = YES;
UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationUnknown == UIInterfaceOrientationLandscapeLeft) {
// UIDevice isn't firing orientation notifications yet… go look at the status bar
curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
}
if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) {
for (NSNumber *orient in self.viewController.supportedOrientations) {
if ([orient intValue] == curDevOrientation) {
forceStartupRotation = YES;
break;
}
}
}
if (forceStartupRotation) {
NSLog(#"supportedOrientations: %#", self.viewController.supportedOrientations);
// The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
UIInterfaceOrientation newOrient = [[self.viewController.supportedOrientations objectAtIndex:0]
intValue];
NSLog(#"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation);
[[UIApplication sharedApplication] setStatusBarOrientation:newOrient];
}
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
return YES; }
I had the same problem (but not using cordova/phonegap).
You have to set your view controller as a RootViewController in your appDelegate instead of just adding as a subview.
Replace in you appdelegate:
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
By
[self.window setRootViewController:self.viewController];
[self.window makeKeyAndVisible];
You can use the delegate
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
Using this delegate and the application will be present in Landscape mode or any desired orientation mode.
Try it.

UIImage Picker autorotation feature disappeared suddenly

I was using UIImagePickerController without any problem.
Before when I was taking a picture in the landscape mode, the picture in the Preview (when the buttons Retake and Use Photo were present) was always automatically rotated so as to appear correctly in the portrait mode.
But now when I use the UIImagePickerController the preview mode does not rotate the picture anymore.
Where can I activate or desactivate this mode?
Here is my code:
- (IBAction)getCameraPicture{
//Create an UIImagePickerController to be able to take a picture
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsImageEditing = NO;
[self presentModalViewController:picker animated:YES];
[picker release];
- (IBAction)selectExistingPicture{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//Here is specified the fact that the picker source is the library
[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];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
int imageCase=0;
UIImage *imageSaved=rotateImage(image);
UIImage* imageNormal =scaleImage(imageSaved,imageCase);
imageView.image = imageNormal;
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
I really need to at least understand what is happening so any help would be really appreciated even if it is not the solution!
Thanks folks!
one possibility is that you need to call
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

Resources