UITextfield to UITextView - An empty line of space appears - ios8

Similarly to this website "Move From UITextField to UITextView When Return Pressed", my cursor appears one line below the intended line. I have tried to use this link as my reference but there didn't seem to be a finalised answer that I could use.
I have also tried
[self.memoTextView performSelector:#selector(becomeFirstResponder) withObject:nil afterDelay:0.0];
but weirdly it work for my simulator but not my device.

Using
[self.memoTextView performSelector:#selector(becomeFirstResponder) withObject:nil afterDelay:0.1];
I am able to navigate from UITextField to UITextView using the Return Key. The error was due to a delay of 0.1 when using the device.

Related

-textFieldShouldBeginEditing is invoked for all textFields rather than when each textField is selected

I have an iPad app (XCode 6.1, iOS 8.1.1, ARC and Storyboards). In one of the classes (scene) I have this code:
-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField { // (prevents keyboard from showing)
if(textField.tag == 200) { // birthdate
[self showModalCalendar:(int)textField.tag];
return NO; // don't show k/b
}
else
return YES;
}
It is executed when the first textField is selected, going through each textField rather than wait until each textField is selected. This is a problem because what I want to accomplish is to show the modal calendar only when a particular UITextField (birthdate) has been selected, and NOT show the keyboard. What's happening is when I tap the tab key (on a hard keyboard) the modal calendar also apprears for each textField.
Is there any way to prevent this?
The problem in my case was IQKeyboardManager library. I removed this library from my project and DownPicker works fine.
Rather than using tags you should create an IBOutlet to the particular textView that you want to handle. Then you can test if textView == your special one in the delegate callback.
The reason is that it is more explicit and clearer than using tags. My guess is that some of your other text views have that same tag for some reason and so your conditional isn't behaving as you think it should.

Adding a UIDatePicker as an inputView to a textField in iOS 8

I have an UIDatePicker in my storyboard view connected to an IBOutlet in the header file.
In the implementation file I set some properties to the picker and then assign it to my textFields:
[self.txtEndDate setInputView:self.picker];
This was working fine in iOS 7, but with iOS 8 it's giving me the following error:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x7c2d8800> should have parent view controller:<InserimentoDurata: 0x7aec2b10> but requested parent is:<UIInputWindowController: 0x7b92b400>'
Any idea on how to fix this?
After receiving an email from Apple's Developer Technical Support, it seems that to add a UIDatePicker (or any custom keyboard for what I've understood) to a viewController, you don't have to add it to its view anymore, but you add it to its title bar and then connect it to the IBOutlet.
It's working for me, even if it doesn't work in the iPhone 5 simulator (all the others are ok) and I was going nuts.
I hope this could be of help for other people with the same problem.
The solution is to build your UIPickerView in code (remove it from the Storyboard), assign it to the textfield's inputView, and retrieve it from there anytime you need it (instead of keeping a reference to it). Basically, this means:
UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 300, 320, 168)];
[picker setDataSource: self];
[picker setDelegate: self];
picker.showsSelectionIndicator = YES;
self.textField.inputView = picker;
If you later need it, use:
UIPickerView* pickerView = (UIPickerView*) self.datePartySizeTextField.inputView;
[pickerView selectRow:1 inComponent:0 animated:NO];
UIDatePicker should not be child of any super view
Problem:
You have to ensure that the view you will assign to inputView or inputAccessoryView don't belong to any parent view. Maybe when you create these views from xib inside a ViewController, by default they are subviews of a superview.
Solution Tips:
Using method removeFromSuperview for the view you will assign to inputView or inputAccessoryView
see detail in this link
Error when adding input view to textfield iOS 8

UISwitch doesn't work on Google Maps SDK for iOS?

I'm trying to create a UISwitch laid on mapView_ of Google Maps for my iOS app, but it seems not to work.
In details, I first followed instruction from google, created mapView_, then made it my viewcontroller's view:
self.view = mapView_;
Then, I created an UISwitch programmatically and added it as a subview:
mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(50, 360, 0, 0)];
[mySwitch setBackgroundColor:[UIColor clearColor]];
[mySwitch addTarget:self
action:#selector(changeSwitch:)
forControlEvents:UIControlEventTouchDown];
[mapView_ addSubview:mySwitch];
But when I touched the switch both in simulator and device, it didn't change its state from ON->OFF or OFF->ON. I even tried different UIControlEvent, such as UIControlEventValueChanged but it didn't work. To make sure that the code should work, I tried on a normal view of a normal test viewcontroller (that means, not using google maps), it worked fine!
Does anyone have any comment about this issue?
Thanks heaps!
You can work around this issue by adding both the UISwitch and the GMSMapView to a single UIView parent, instead of adding the UISwitch as a child of a GMSMapView. Yes, this means you need to position both the GMSMapView and the UISwitch.

Xcode 4.3: duplicated connections of an IBOutlet

I am learning Stanford CS193p course with Xcode 4.3.3. I think the screenshot below is pretty much self-explaining. But i will describe the problem with words anyway.
I control-drag a UILabel from storyboard to corresponding implementation file to make the IBOutlet #property. Then I see two connections displayed when clicking the filled circle in the left side of the editor where shows line numbers. I don't know how to delete it.
Moreover, I see only ONE connection in storyboard's connections inspector of the UIlabel.
More weird, when I try to set the UILabel's text inside the setter of a public preperty, it fails to update the label's text:
-(void) setQuestion:(NSString *)question
{
_question = question;
self.questionLabel.text = question;
NSLog(#"The quesion is %#",question);
NSLog(#"The quesion label text is %#",self.questionLabel.text);
}
I use two NSLog to debug and get the following. It shows the NSString *question is #"What do you want your label to say?", yet the self.questionLabel.text is null. The value assign fails. I suspect this relate to the duplicated connections thing mentioned above.
2012-07-29 04:03:53.817 Kitchen Sink[18628:f803] The quesion is What
do you want your label to say?
2012-07-29 04:03:53.820 Kitchen
Sink[18628:f803] The quesion label text is (null)
The following is the screenshot showing the duplicated connections. I am probably missing something obvious, please help.
I would stalk this up to Xcode storyboard wonkiness.
First, try a clean of the project and a re-build.
Should you still have that problem, manually define the #property without dragging from the AskerViewController view to the AskerViewController implementation (.m) file by doing the following.
Cut that IBOutlet #property line in the interface section of the implementation (.m) file for AskerViewController. Click the label in storyboard. Disconnect any binding that label to the AskerViewController. Clean the project. Then, paste back in the property, and control-drag from the label to the view controller orb at the bottom of the AskerViewController view in your storyboard file.

NSWindow is not displaying

I am having a trouble try to display a NSWindow with out using Interface Builder. The initialization of the window was quite confusing since I am more familiar with iPhone (which does not have an NSWindow equivalent). So I searched Google for some code and I eventually found this:
NSRect windowRect = NSMakeRect(10.0f, 10.0f, 800.0f, 600.0f);
NSWindow *window = [[NSWindow alloc] initWithContentRect:windowRect
styleMask:( NSResizableWindowMask | NSClosableWindowMask | NSTitledWindowMask)
backing:NSBackingStoreBuffered defer:NO];
[window makeKeyAndOrderFront:nil];
So I copied that code and placed it in the applicationDidFinishLaunching and thought all would be good. But all is not good. Xcode did not display any errors (or warnings) in the Build Results. But, I do get this message in the display log:
2010-06-26 13:33:47.170 FooApp[283:a0f] Could not connect the action buttonPressed: to target of class NSApplication
I don't know how to interpret this as Google has failed me on searching for a solution on this display log error. And, as far as I can tell, I have no actions at the moment including a buttonPressed one. As a side note: I do not know if this is relevant or not, but I deleted the Main Window.xib and its accompanying property in the info.plist.
Any help would be greatly appreciated.
UPDATE: I tried doing some printf debugging (never really bothered learning NSLog) and the thing won't even printf if the thing is at the very beginning of the appliactionDidFinishLaunching or even worst, at the start of main (before the return if incase some of you are tempted to ask me if I put the printf before or after the return statement).
MainWindow.xib is part of the iphone App template, isn't it? What exactly did you delete? You still have the MainMenu.xib, right?
As you have discovered, having a nib file is not optional for a Cocoa app. You must have at least one nib (or xib, for you youngsters) and it must have a main menu in it.

Resources