Unrecognized selector setting alpha for a UIImageView - ios

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!

Related

Facebook pop kPOPLayerCornerRadius is not working

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"];

Creating a CGRect as an Associated Object?

I'm attempting to create a CGRect property for my UIButton's as an associated object, so that I don't have to subclass UIButton just for this.
Basically I'm adding a property titled, tapArea, and I'm having trouble creating it. This is what I have so far:
#dynamic tapArea;
- (void)setTapArea:(CGRect)tapArea {
objc_setAssociatedObject(self, #selector(tapArea), [NSValue valueWithCGRect:tapArea], OBJC_ASSOCIATION_ASSIGN);
}
- (CGRect)tapArea {
return [objc_getAssociatedObject(self, #selector(tapArea)) CGRectValue];
}
When I NSLog say dogButton.tapArea, the logger prints out {{0,0},{0,0}} which makes sense. The problem arises when I attempt to set it. I get the following crash:
-[__NSCFString CGRectValue]: unrecognized selector sent to instance 0x14e65e80
I believe I'm getting this error bc I'm using NSValue, but I'm not pulling it back out correctly. How can I fix my getter?
P.S. This is how I'm declaring my property in my category header file:
#property (nonatomic, assign) CGRect tapArea;
Also, how can I set my property equal to the button's frame by default instead of {{0, 0}, {0, 0}}?
You're working awfully hard to avoid subclassing a UIButton, which is pretty damn easy and quick. Don't make it more complicated than necessary.
Also, an NSValue is an NSObject which should be retained not assigned. Your storage semantic is incorrect, which is probably why you are having problems. Your associated object is an object and needs to be retained like an object.
Use OBJC_ASSOCIATION_RETAIN_NONATOMIC

Why is UITextField text setter giving [UIView text] selector not recognized

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 :-)

NSInvalidArgumentException in Objective C

I'm making a simple calculator and when I use the addition button, the iOS Simulator crashes and I get an NSInvalidArgumentException. What do I do to prevent this from happening?
Error Report:
2013-06-23 17:18:54.574 Tutorial Test (Storyboard)[9744:c07] -[ViewController2 addition]:
unrecognized selector sent to instance 0x75858f0
2013-06-23 17:18:54.577 Tutorial Test (Storyboard)[9744:c07] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController2 addition]:
unrecognized selector sent to instance 0x75858f0'
*** First throw call stack:
(0x1c91012 0x10cee7e 0x1d1c4bd 0x1c80bbc 0x1c8094e 0x10e2705 0x162c0 0x16258 0xd7021
0xd757f 0xd66e8 0x45cef 0x45f02 0x23d4a 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962
0x1c37bb6 0x1c36f44 0x1c36e1b 0x1beb7e3 0x1beb668 0x12ffc 0x1e2d 0x1d55)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Code in ViewController that has this error:
View Controller.h
#import <UIKit/UIKit.h>
//Calculator
#interface ViewController2 : UIViewController{
IBOutlet UITextField *textField1;
IBOutlet UITextField *textField2;
IBOutlet UILabel *label;
}
-(IBAction)addition;
-(IBAction)subtract;
-(IBAction)multiply;
-(IBAction)divide;
-(IBAction)clear;
#end
View Controller.m
//Addition
-(IBAction)plus
{
float a = ([textField1.text floatValue]);
float b = a+([textField2.text floatValue]);
label.text = [[NSString alloc] initWithFormat:#"%2.f", b];
}
You named the method in the .m file plus, rather than addition. That is why the method addition isn't found, and the fix would be to rename the method in the .m file from plus to addition:
//Addition
-(IBAction)addition
{
float a = [textField1.text floatValue];
float b = [textField2.text floatValue];
label.text = [[NSString alloc] initWithFormat:#"%2.f", a+b];
}
Have you allocated an instance of the ViewController2 class?
For example:
ViewController2 *vc2 = [[ViewController2 alloc] init];
[vc2 addition];
Also, if the .m code you posted is the full contents of that file, then you're also missing
-(IBAction)addition {
...
}
You didn't inplement the right method.
You call addition but you never actually implement it. Declaring the method signature in the .h is not enough, you have to code the method.
This means that the selector that you are calling is not available on the class you called it against. The best thing to do is place a breakpoint where the method is being called. Go to the debugger and po your object.
po 0x75858f0
in this instance. However that number could be an object and it could be different. Look at the number in the console.
Make sure the object is of the proper class. Then check that class to make sure it responds to the selector you are calling.
Edit: Your problem is that your plus method should be renamed to addition. The names in the .h must match the names in the .m

weird problem with UILabel

I am using UILabel for custom cells in my UITableView. Heres all the code that I am using :
header file:
UILabel *timeLabels;
#property (nonatomic, retain) UILabel *timeLabels;
code file:
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
timeLabels=[[UILabel alloc] init];
timeLabels.textAlignment=UITextAlignmentLeft;
timeLabels.font=[UIFont boldSystemFontOfSize:12];
timeLabels.backgroundColor=[UIColor clearColor];
timeLabels.textColor=[UIColor blueColor];
- (void) layoutSubviews
frame=CGRectMake(boundsX+5, 5, 60, 45);
timeLabels.frame=frame;
[timeLabels release]
I am getting the following error on timeLabels.frame=frame;
2011-08-08 12:44:07.290 EncameoApp[2014:707] -[NSCFString setFrame:]: unrecognized selector sent to instance 0x136890
2011-08-08 12:44:07.361 EncameoApp[2014:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString setFrame:]: unrecognized selector sent to instance 0x136890'
Which is pretty strange given that timeLabels is not a NSString, but rather a UILabel !
Can anyone please let me know what I missed here ? Thanks.
I also faced this kind of problem, but i had solved this problem by set value of timeLabels as following:-
timeLabels.text = #"value";
instead of
timeLabels = #"value";
The code snippet you show is correct, anyway my guess is that you have very possibly a memory problem that makes your UILabel instance to be released at some point before layoutSubviews is executed, then that memory is reused by an NSString, so you get the error there.
In my experience, the most common case for this to happen is anyway erroneously overwriting timeLabels with the wrong value could produce the same result. This could be done within the class or from another class (that maybe tries to set the label value).
If you want to make a simple test, add
NSLog(#"timeLabels address %x", timeLabels);
both to init and to layoutSubviews to compare the two values and see that they differ (or maybe they don't, in this case you would have a memory corruption problem).
You should inspect your code, and post more of it if you need more help.

Resources