Difficulty implementing delegate methods in an objective-c project - objective-c

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.

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.

auto scroll uipickerview when button is clicked

I am using a UIPickerView to display answers to a question. There needs to then be a button to reveal the correct answer if the user cannot work it out. I have tried the below, but the app crashes. How can i autoscroll to the correct answer?
-(void)reveal {
[myPickerView selectRow:0 inComponent:0 animated:YES];
}
EDIT: Yes i am just trying to get it to scroll to the first answer in the above example :)
[ExcerciseController reveal:]: unrecognized selector sent to instance 0x68398f0
2012-10-30 14:57:21.673 English[20786:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ExcerciseController reveal:]: unrecognized selector sent to instance 0x68398f0'
* First throw call stack:
(0x1397022 0x108ccd6 0x1398cbd 0x12fded0 0x12fdcb2 0x1398e99 0x1f214e 0x1f20e6 0x298ade 0x298fa7 0x298266 0x2173c0 0x2175e6 0x1fddc4 0x1f1634 0x21a3ef5 0x136b195 0x12cfff2 0x12ce8da 0x12cdd84 0x12cdc9b 0x21a27d8 0x21a288a 0x1ef626 0x2c5d 0x2b85)
terminate called throwing an exception[Switching to process 20786 thread 0xf803]
Now, that the error/crash message is visible, it turns out that the error is not in how you call the picker's method. It is how you invoke reveal.
You call reveal with some object. Or you call it by passing a selector. However, the current selector that you are calling is reveal: but the methods name is reveal without any parameter. reveal: would require one parameter.
Wherever you call it, make sure that you call reveal and not reveal:
I assume you set the selector either in interface builder or when creating the button programmatically. That is the place where you made the mistake.
Some background:
The error message tells you what you need to know. A method name is called selector in Objective-C at runtime. In some literature you will find the wording of a message (named reveal: in your case) is sent to a receiver named ExcerciseController in your case.
Objective-C is polymorph. That means that reveal (called without any parameters) refers to another method implementation than reveal: (called with one parameter) or even reveal:: (called with three parameters).
myPickerView may not be the instance of UIPickerView as UIPickerView responds to selector - (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
Or you have to check how the method reveal is invoked.
please try to post the crash description,Need more blocks of code to answer it :)
However just try the below code
myPickerView.delegate = self;
[myPickerView reloadAllComponents];
[myPickerView selectRow:0 inComponent:0 animated:YES];

To View ProfilePicture in Xcode of facebook user

When i am using
self.profilePic.profileID = user.id;
i end up with this error
-[UIView setProfileID:]: unrecognized selector sent to instance 0x69626f0
2012-09-11 09:49:50.535 TweetApp[992:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setProfileID:]: unrecognized selector sent to instance 0x69626f0'
can anyone help on this topic??
You can fix this issue simply. Just put this line code [FBProfilePictureView class]; at the first line of method application:didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBProfilePictureView class];
//...
return YES;
}
I believe you are talking about Facebook Scrumptious sample project. If that is the case, you have to set the Class of UIView control to FBProfilePictureView
I had the same problem, itsaboutcode is right. Call [FBProfilePictureView class]; in your AppDelegate and the problem will be fix
++
Let's do it step-by-step.
self.profilePic refers to your property of UIView type.
Then you are trying to set this property's property profileID, but UIView class doesn't have such and you get the exception.
It will be easy for you to understand in the future from the error message, pay attention to the reason:
'-[UIView setProfileID:]: unrecognized selector sent to
instance 0x69626f0'
It tells you the method -setProfileID: is called for UIView* object and with the code you posted it is clear why it happens.
I suppose you have profileID property in the view controller, then you'll want to use
self.profileID = user.id;
Or if self.profilePic should support profileID property then you initialized it incorrectly, find the initialization place to see what happens.
I faced the same problem make sure your profile pic is an instance of FBProfilePictureView go to your layout and change the class of your view to be FBProfilePictureView notice your fb profile pic is a UIView not an ImageView that means u need to add view and change its class to FBProfilePictureView not an ImageView
also add this line at the first of your app delegate [FBProfilePictureView class];

[__NSCFType searchKeyword:]: unrecognized selector sent to instance 0x6d8eb80

The following code is to add a subview to current view from storyboard:
EventSearchViewController* view1 = [self.storyboard instantiateViewControllerWithIdentifier:#"searchView"];
[view1 setBookingSystem:system];
[self.view addSubview:view1.view];
In the view "view1", there is a textField. The following is a IBAction to the textField and the event is "Did end on exit".
-(IBAction)searchKeyword:(id *)sender
{
NSLog(#"searchKeyword");
}
The following is the error message.
2012-05-26 20:26:47.369 OnlineBooking[6607:f803] -[__NSCFType searchKeyword:]: unrecognized selector sent to instance 0x6d8eb80
2012-05-26 20:26:47.369 OnlineBooking[6607:f803] * WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: -[__NSCFType searchKeyword:]: unrecognized selector sent to instance 0x6d8eb80
You need to retain your EventSearchViewController, or keep a strong reference to it if you're using ARC. If you assign it to view1 as a local variable, it's not going to be around any more when searchKeyword: gets called. (The error shows that its memory has been released and re-used for a different type of object.)
For me the problem was that I never called
- (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
before I called
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
again.

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.