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.
Related
Note: This crash only occurs in iOS 9
I have this subclass:
#interface PTSwitch : UIControl
#property (nonatomic) BOOL on;
#property (nonatomic) NSInteger identifier;
- (void)setOn:(BOOL)on animated:(BOOL)animated;
#end
When I try to access the "identifier" property...
alertSwitch.on = YES;
alertSwitch.identifier = 1;
...I get an exception:
-[PTSwitch setIdentifier:]: unrecognized selector sent to instance
I have verified in the debugger that the object is indeed my subclass. Additionally, as you can see, called immediately before identifier is the on property, which is accessed without a problem.
po alertSwitch
<PTSwitch: 0x1383620f0; baseClass = UISwitch; frame = (257 62; 51 31); alpha = 0.5; autoresize = RM+BM; tag = 666; layer = <CALayer: 0x136dd1800>>
po [alertSwitch class]
PTSwitch
EDIT
I just noticed that the debugger seems to think the base class is UISwitch. I have no idea why this is, as clearly the base class is UIControl. I have no explanation for this but suspect it might be related.
Side note, this crash began happening on a version that was built with Xcode 7 for iOS 8 and was not rebuilt to cause the app to start crashing.
#rmaddy, that was a very helpful hint
I did a quick search for "PTSwitch" on google and found a reference to a runtime header in iOS 8.3+. I'm not sure why I did not experience this crash until iOS 9, but it is definitely resolved now.
Solution: rename class to something other than PTSwitch.
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
I am new to using this method so I could be doing this completely wrong so here is my code:
#property (nonatomic, weak) ConverterViewController *converterViewController;
#property (nonatomic, weak) CalculatorViewController *calculatorViewController;
If I am understanding this code correctly, these are acting as references to Two different ViewControllers.
Then I have this in my viewDidAppear method:
[self addChildViewController:_converterViewController];
[_converterViewController didMoveToParentViewController:self];
[self.view addSubview:_converterViewController.view];
I am getting an NSException at the first line when I try and add it as a child view controller. So not knowing whether or not this should then call some methods in my ConverterViewController class I put some breakpoints within that class both the initWithNibName and viewDidLoad methods and I found that neither of these methods are being called, so Im not exactly sure what is wrong. Then again Im not really sure what could go wrong so any help is greatly appreciated.
This is all I get from the console:
libc++abi.dylib: terminating with uncaught exception of type NSException
Updated Answer:
[self addChildViewController:_converterViewController]; does not create the converterViewController.
It simply takes the converterViewController object and adds it as a childViewController to self.
You will need to allocate memory and instantiate the object converterViewController before -addChildViewController: or else it's value will be nil and nothing will happen.
So... something this:
_converterViewController = [[ConverterViewController alloc] initWithNibName:#"ConverterViewController"
bundle:nil];
//now... adding it as childViewController should work
[self addChildViewController:_converterViewController];
[_converterViewController didMoveToParentViewController:self];
//optional: give it a frame explicitly so you may arrange more childViewControllers
//[_converterViewController.view setFrame:CGRectMake(0,0,100,100)];
[self.view addSubview:_converterViewController.view];
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 need to create a number of UIScrollViews dynamically and fill them with content. This is all good except when i set the delegate to self and pan the list i get this exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString scrollViewDidScroll:]: unrecognized selector sent to instance 0x7581230'
NSCFString obviously isn't my view controller (which implements the protocol UIScrollViewDelegate) so from what i gather somehow the memory gets messed up and it doesn't keep the reference correctly. Occasionally this can be something else too which strongly points to something being wrong with the memory
Here's the code to create the list:
for (NSUInteger i = 0; i < self.stories.currentStory.selectableWordCount; i++) {
UIScrollView *list = [[UIScrollView alloc] init];
list.alwaysBounceVertical = YES;
list.showsVerticalScrollIndicator = NO;
list.clipsToBounds = NO;
list.delegate = self;
list.pagingEnabled = YES;
[self.view addSubview:list];
.. // add UILabels to the list, set the frame, contentSize etc
[self.wordLists addObject:list]; // this is a #property (nonatomic, strong) NSMutableArray, declared in a private interface()
}
If i NSLog the delegate it's correct. respondsToSelector also matches fine. Interestingly if i comment out the scrollViewDidScroll: respondsToSelector: doesn't match any more and (probably because of this) the UIScrollView won't attempt to call this method any more. This then means that it can reach the delegate correctly to check for the method availability but when it gets called something goes wrong.
I'm targeting iOS5 with ARC. If this wasn't the case i would assume that i messed something up with the memory myself but now i don't have the same control.
I'm having a hard time debugging this issue, any help on how to proceed would be appreciated
D'uh. I was obviously looking in the wrong place. The view controller was added through a .xib and the view was pointing to a subview on the stage. However i needed to create an IBOutlet to the view controller in the main view controller to make sure it stays in memory. Hopefully this can help somebody else with a similar problem :)