I have this code:
- (IBAction)setButtonPressed:(id)sender {
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:#"group.TodayExtensionSharingDefaults.santiapps.com"];
NSLog(#"nsuserdef %#", [sharedDefaults objectForKey:#"MyNumberKey"]);
NSLog(#"self.textField.text %#", self.textField.text);
//[sharedDefaults setInteger:[self.textField.text integerValue] forKey:#"MyNumberKey"];
[sharedDefaults synchronize]; // (!!) This is crucial.
NSLog(#"syncd");
}
and for some reason when I tap the button, I get:
-[UIView text]: unrecognized selector sent to instance
but my property is set as:
#property (weak, nonatomic) IBOutlet UITextField *textField;
I get a crash if I uncommment the sharedDefaults setInteger line.
I get a crash if I leave the line where I read the self.textField.text.
I get the final syncd NSLog only if I comment-out the setInteger or self.textField.text NSLog lines.
Why is it thinking textField is a UIView without a text property?
Ok, don't mean to toot my own horn here, but I thought the answer might help someone.
Xcode had incorrectly linked my view controller's UIView to the outlet. And I know some will think I would have done it by being careless, except that I did it as I very seldomly do the connection:
I control dragged from the textfield to the assistant editor's interface where xcode itself created the IBOutlet UITextField for me. So I know it wasn't my mistake. :)
Xcode is buggy. So watch out :-)
Related
I'm actually in big troubles on how to get the Text from a TextField (and optionally a TextView ).
I'll try to make it simple: I have my PostIt.xib which is composed of 2 labels (which I don't really care about) and also one TextField and one TextView. Here is how I tried to get the text from these:
First, in my PostIt.h :
#interface PostIt : UIView {
IBOutlet UITextField *titre;
IBOutlet UITextView *commentaire; }
Then secondly, in my PostIt.m : (the real action of this method is that it close a view and normally throw back the information I want to get to another view, here: parent )
-(IBAction)doubleTap:(UITapGestureRecognizer *)recognizer{
[_parent setTitre:titre.text];
[_parent setCommentaire:commentaire.text];
[_parent setIsEdited:true];
[self removeFromSuperview]; }
My problem here is, when I call a NSLog (for example) to show me the Strings which are caught (probably a mistake here? sorry) it show me every time : (null)
I have been looking and trying a lot of answer i found but no one seems to be able to solve my problem...
If someone could help me it will be really nice, thanks in advance :)
Is there any more code pertaining to the UITextField?
Based on what I see here you need you first convert the input from the UITextField
into a string and then you can set the string where you want.
Updated to add the conversion code,
NSString *stringFromTextField = [yourTextField text];
Here is some more details,
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UITextField *yourTextField;
#end
Your Action,
- (IBAction)yourAction:(id)sender {
//Converting UItextfields into strings
NSString *stringFromTextField = [self.yourTextField text];
}
Here is a sample project I made for you on GitHub -
stringFromTextView
You should try to input to your code an object part if that's not already done, where you could directly pick up the data that you need and that's also from here that you should update your view.
I have outlet from storyboard and pop animation code inside of IBaction (UIButton) :
#property (strong, nonatomic) IBOutlet UIView *animationView;
...
...
POPBasicAnimation *animationCircle = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerCornerRadius];
animationCircle.toValue = #(self.animationView.layer.cornerRadius/2);
animationCircle.name = #"animacijaCircle";
animationCircle.delegate = self;
[self.animationView pop_addAnimation:animationCircle forKey:#"animacijaCircle"];
My animation is not working and I don't know why...
I have this in my debug area:
2015-03-17 11:28:00.321 customControll[5759:325909] -[UIView cornerRadius]: unrecognized selector sent to instance 0x7fc79ac720c0
and my exception breakpoint os stoped on this part of pop framework:
{kPOPLayerCornerRadius,
^(CALayer *obj, CGFloat values[]) {
values[0] = [obj cornerRadius];// exception breakpoint is on this line here
},
^(CALayer *obj, const CGFloat values[]) {
[obj setCornerRadius:values[0]];
},
kPOPThresholdRadius}
You can also give me example of cornerRadius animation with pop that I can use, I just want to make it work with Facebook pop.
Thank you!
kPOPLayerCornerRadius is a layer property not a view property therefore you need to add the animation to the layer not the view. So this line:
[self.animationView pop_addAnimation:animationCircle forKey:#"animacijaCircle"];
should be:
[self.animationView.layer pop_addAnimation:animationCircle forKey:#"animacijaCircle"];
I'm getting an unrecognized selector exception trying to set the alpha on a UIImageView, but I don't understand why this should be seeing a UIImageView inherits from UIView and alpha is a property of that.
#property (strong, nonatomic) IBOutlet UIImageView *pulldownTab;
...
self.pulldownTab.alpha = 1.0;
2013-05-21 07:33:32.964 TestControl[655:907] -[__NSCFNumber setAlpha:]: unrecognized selector sent to instance 0x1e587fa0
** UPDATE **
Moral of the story - Solved. be careful with key value coding, a call to this function was being made earlier
- (void) fadeToAlphaValue: (double) alpha forKeyPath: (NSString*) keyPath
{
NSNumber* number = [NSNumber numberWithDouble:alpha];
[UIView animateWithDuration:kFadeAnimationDuration
animations:^ {
[self setValue:number forKeyPath:keyPath];
}];
}
[self fadeToAlphaValue:0.0 forKeyPath:#"self.pulldownTab"];
Are you sure you are assigning the IBOutlet properly in the interface Builder?
The reference is not properly working, when you access to self.pulldownTab is accessing to a NSCFNumber variable in memory.
I had the same problem here. In my case, I was setting myTextView, but not the .text property, earlier in the code, like this:
self.myTextView = #"text";
instead of what I should have been doing:
self.myTextView.text = #"text";
for some reason this didn't throw any errors at this point, but it created an issue later when I tried to set the alpha property on an NSString (which doesn't have such a thing) :)
Anyways, just look for any stupid mistakes like this in your code before the .alpha property is being set - they'll likely be the cause of the problem!
I thought this would be pretty simple but apparently it isn't, at least not to me. I have a UITextField declared in my .h file and declared its property, as well as an IBAction to clear the text within the field.
IBOutlet UITextField *textField1;
#property(nonatomic, retain) UITextField *textField1;
-(IBAction)clearText:(id)sender
Then in my implementation file (.m) this is how I've written the method to clear the text.
-(IBAction)clearText:(id)sender {
textField1.text = NULL;
}
But nothing happens when I press the button in the simulator. Why?
Did you actually connect the outlet?
Also I'd suggest using nil or #"" instead of NULL
This must work:
textField1.text = #"";
further check if the outled of textFiel1 is connected (black filled circle in XCode)
Add a log statement to
-(IBAction)clearText:(id)sender {
NSLog(#"clearText");
textField1.text = #"";
}
to see if it is called.
If it is not called, check the outled for clearText:(id)sender , too.
I have an UITextField inside an UITableViewCell. What I want't is for the app to save the text the user inputs. I've tried by making the UITextField call a action with this code:
[TextField addTarget:self action:#selector(saveTextField:) forControlEvents:UIControlEventEditingDidEndOnExit];
However this action that it load doesn't work correctly:
- (IBAction)saveTextField:(id)sender {
NSString *TextFieldString = [[NSString alloc] initWithString:TextField.text];
[TextField setText:TextFieldString];
NSUserDefaults *UserSettings = [NSUserDefaults standardUserDefaults];
[UserSettings setObject:TextField forKey:#"TextField"]; }
When I exit the UITextField by trying to hide the keyboard by clicking "Done" I get this message:
*** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSInvalidArgumentException> *** -[NSPlaceholderString initWithString:]: nil argument
and nothing happens in the app.
Any thoughts?
Thanks in advance :)
I use the exact same functionality in one of my apps, and this is the code I use:
[[NSUserDefaults standardUserDefaults]setObject: textField.text forKey:#"TextField"];
Basically, I don't think the first two lines in your saveTextField method where you alloc a new string are necessary.
To begin with: thanks for your effort and time :)
Turns out the problem wasn't with the code that saves and loads it. The problem was that I only created one UITextfield which I then put into every UITableViewCell and that was the problem. So I created individual UITextFields for every UITableViewCells and that fixed the problem :)