Stupid crash when setting collection cell frame - objective-c

It might be something stupid and i am doing this for years, but i just cant figure this one out .
In my collection view cell class i have this :
- (void)layoutSubviews
{
self.title.frame=CGRectMake(50, 50, 100, 100);
}
the cells are ok only if i remove this line of the frame settings, if not, i get :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString setFrame:]: unrecognized selector sent to instance 0x7fdcbbd0afb0'
everything is set, and i didn't miss a thing, i already done that many times.
What is this ??
EDIT:
#property(nonatomic,strong) UILabel *title;

Oh no... thanks to the help of the good people here, i found out that i do this
cell.title=[dic objectForKey:#"title"];
instead of this
cell.title.text=[dic objectForKey:#"title"];
so it turned to a string ! (??)

Related

Objective-C Code throws 'Unrecognised Selector' for the 'sender' selector

I am fairly new to apps and Objective-C as a whole. I was creating a slider that sends it's output to a label displaying the number. Here is the code:
- (IBAction)sliderChanged:(id)sender {
UISlider *slider = (UISlider *)sender;
self.sliderText.text = [NSString stringWithFormat:#"%f", slider.value];
}
And behold the error:
2014-01-10 17:17:29.037 tapbuttonipad[64226:70b] -[NSViewController sliderChanged]: unrecognized selector sent to instance 0x8a6f450
2014-01-10 17:17:29.061 tapbuttonipad[64226:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSViewController sliderChanged]: unrecognized selector sent to instance 0x8a6f450'
The slider is linked to that block of code. I am unsure as to what I am doing wrong.
Any help is greatly appreciated.
EDIT:
Someone who answered but then deleted their answer was actually correct, and now my app does not crash. However, the app still does not update the label that it was meant to. I changed it from setting the value to just setting #"test", but it still did not change.
ANOTHER EDIT:
Darn, I am stupid. I had my label variable as a text field instead of a label... gah! Anyway, this is completely fixed now. Thanks everyone!
You should change the class of your view controller in your xib/storyboard to your NSViewController subclass:
Select your view controller in object inspector
In Identity inspector specify the name of your NSViewControllerSubclass in Custom Class field
Alright. I have fixed it. Firstly, it would throw an error as the slider was linked to the IBOutlet when it was without a colon, and I did not update it. After updating it worked fine.

Difficulty implementing delegate methods in an objective-c project

I have a table view which I am using as a form.
The first cell has an editable text field. The second cell, when clicked, loads a semi modal date picker. I used this: http://reednj.tumblr.com/post/1346445326/ios-semi-modal-date-picker-for-iphone
Anyway, I've defined my datepicker and set its delegate inside the tableviewcontroller like so:
TDDatePickerController* datePickerView = [[TDDatePickerController alloc]
initWithNibName:#"TDDatePickerController"
bundle:nil];
[datePickerView setDelegate:self];
[self presentSemiModalViewController:datePickerView];
Now the methods to handle the button clicks are defined as
-(void)datePickerSetDate:(TDDatePickerController*)viewController;
-(void)datePickerClearDate:(TDDatePickerController*)viewController;
-(void)datePickerCancel:(TDDatePickerController*)viewController;
So when the cancel button is pressed I would like the semi-modal date picker to be dismissed, So I've got:
-(void)datePickerCancel:(TDDatePickerController*)viewController{
[self dismissSemiModalViewController:viewController];
}
But this makes the app crash with the error
-[__NSCFType cancelDateEdit:]: unrecognized selector sent to instance 0xe738c00
2012-09-18 10:23:47.254 JRPBaseCamp[7612:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType cancelDateEdit:]: unrecognized selector sent to instance 0xe738c00'
So I looked up the cancelDateEdit method in TDDatePickerController:
-(IBAction)cancelDateEdit:(id)sender {
if([self.delegate respondsToSelector:#selector(datePickerCancel:)]) {
[self.delegate datePickerCancel:self];
}
}
What am I doing wrong? It must be something obvious that I'm overlooking. Any help is much appreciated, I'm fairly new to iOS and the whole concept of delegates is really confusing me.
Thanks!
The unrecognized selector sent means nothing is responding to cancelDateEdit: selector. You can use the debugger to search what kind of object is 0xe738c00 and then look for the appropriate selector there.

Array not retaining properly?

I get the following error when running my App:
2011-09-02 15:38:44.157 TheApp[9973:207] -[NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x4b28990
2011-09-02 15:38:44.160 TheApp[9973:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x4b28990'
And Xcode marks the line in this function in green:
- (void)oneCheckAndSetStrokes {
playerOneScoreNum.text = [playerOneScore objectAtIndex:(11)]; }
Therefore I'm guessing something is messed up with the Array. After som research I came across a lot of posts like this one: NSMutableArray : unrecognized selector sent to instance which seems to inticate that the error occurs when the Array is not being retain properly (hence my title).
So I'm trying to retain the Array in the file in wich it is initiated (which by the way is not the same file as the code above. The Array is also defined in another file, Globals.h, and then imported), in the following way:
- (void)viewDidLoad {
[super viewDidLoad];
playerOneScore = [[NSMutableArray alloc] initWithCapacity:19];
[playerOneScore retain]; }
This would solve the problem according to the post refered to earlier, but in my case it does not. Has anyone encountered something similar? It seems like I'm missing something trivial here.
The error you got has nothing to do with retain, you got that error because at this line:
playerOneScoreNum.text = [playerOneScore objectAtIndex:(11)];
you are trying to set a string property using a number object! You have to use "stringValue", in this way:
playerOneScoreNum.text = [[playerOneScore objectAtIndex:11] stringValue];
ps: wrapping the index (11) with parenthesis is useless :P

How to Assign a UITextField to a NSString (with UITouchEvent error?)

I'm simply trying to assign a UITextField.text to an NSString in my object.
The code errors out when I try to print the enteredLocation.text but I have no idea why. I thought it was a type mismatch, but both are NSString. Any idea?
- (IBAction) submitPushed: (UITextField*)enteredName: (UITextField*)enteredCell: (UITextField*)enteredLocation;
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
NSLog(#"LOC %#", enteredLocation.text);
theDataObject.location = enteredLocation.text;
NSLog(#"DATAOBJ %#", theDataObject.location);
}
I always get this error:
2011-08-20 10:28:13.602 ViewControllerDataSharing[3188:207] -[UITouchesEvent text]: unrecognized selector sent to instance 0x4e07780
2011-08-20 10:28:13.607 ViewControllerDataSharing[3188:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITouchesEvent text]: unrecognized selector sent to instance 0x4e07780'
But UITouchEvent? How does that relate? I ctrl-clicked the button to the method in my .m file. Is there a step missing? I tried checking if the text is "", but it won't even get that far.
I have the I'm a major newbie, so thanks in advance. I've read 100s of answers on this site, and love it!! So helpful!
THANKS!
Mark
When the action fires for your button, the method signature will look like one of these:
-(IBACtion)onPushed; // no parameters
-(IBAction)onPushed:(id)sender; // sender is the control that initiated the event
-(IBAction)onPushed:(id)sender event:(UITouchesEvent*)event; // event is the touch event that caused the event
You can't control what gets passed to your handler by changing the parameters. If you need to access the text field, make sure there is an IBOutlet reference to the UITextField object in your class (and hook it up in IB) and use that to access it.
I'm guessing that you have the IBAction hooked up to the wrong action in your nib - one that is a touch event. If you try:
NSLog(#"Param1: %#", enterdLocation);
You'll see that the method is being passed a UITouchesEvent object instead of a UITextField object.
Double-check your nib connections.

[UILabel setAnswerText:]: unrecognized selector sent to instance 0x4916830'

so i am getting an uncaught exception and im not sure why. this is the error i get:
2010-08-22 10:39:25.080 MayanGlyphs[10903:207] * -[UILabel setAnswerText:]: unrecognized selector sent to instance 0x4916830
2010-08-22 10:39:25.081 MayanGlyphs[10903:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UILabel setAnswerText:]: unrecognized selector sent to instance 0x4916830'
also i am getting a warning that UILabel may not respond to setAnswerText (answerText is the name of the label) even though i have created the outlet, connected it in IB, and synthesized it.
does anyone know why this might be happening?
answerText is the name of the label? then what are you trying to do?
If you want to access the answerText object (that being an instance of UILabel) you need to use self.answerText not [UILabel setAnswerText];
If you want to change the text in the label use:
answerText.text = #"Hello, this is my text";
or similar.
You need to do [setAnswerText setText:#"my text"]; What you are doing now is wrong. The reason you get that exception is that UILabel does not have a class method called setAnswerText:.