Unrecognized selector sent to instance - iphone

Anyone know why I am getting this error?
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomRaisedTabViewController cancel:]: unrecognized selector sent to instance 0x4d321e0'
This is the code where it is failing. This is in my CustomTabViewController. The error is happening when I click my "Cancel" button.
-(IBAction)showPostModalViewController {
PostActionModalViewController *addController = [[PostActionModalViewController alloc]
initWithNibName:#"PostActionModalView" bundle:nil];
// Configure the PostAddViewController. In this case, it reports any
// changes to a custom delegate object.
addController.delegate = self;
// Create the navigation controller and present it modally.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
UIBarButtonItem *cancelButton =
[[UIBarButtonItem alloc] initWithTitle: #"Cancel"
style: UIBarButtonItemStylePlain
target: self
action: #selector(cancel:)];
addController.navigationItem.rightBarButtonItem = cancelButton;
[cancelButton release];
//[self presentModalViewController:addController animated:true];
[navigationController release];
[addController release];
}
-(IBAction)cancel {
[self.parentViewController dismissModalViewControllerAnimated:YES];
}

Because the cancel: method is not cancel which is what you've defined.
Change your cancel action to look like this:
- (IBAction)cancel:(id)sender {
...
}

action: #selector(cancel:)
For the action selector which takes parameter! cancel: that means which will take another parameter.
change your method to
-(IBAction)cancel:(id)sender{
// Do wat you want
}
or
-(IBAction)cancel:(UIButton *)btnSender{
/// Do what you want
}

you have to modify the cancel method signature in
-(IBAction)cancel:(id)sender
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
when you added the action to your cancelButton (during initialization) you specified the "cancel:" selector, this means that it will be called a method having one parameter (the sender button)

Related

Unrecognized selector sent to instance (with UIBarButtonItem)

In my iPhone application I have such code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Instruction Controller";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(menuButtonClicked)];
}
#pragma mark private methodes
-(void) menuButtonClicked{
NSLog(#"menuButtonClicked");
}
But when I click on this button it raise an exeption: "Unrecognized selector sent to instance". How cam I resolve this issue?
UPDATE
2013-05-23 12:21:33.182 CICDP[3091:11603] -[__NSCFString menuButtonClicked]: unrecognized selector sent to instance 0x8128eb0
2013-05-23 12:21:33.188 CICDP[3091:11603] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString menuButtonClicked]: unrecognized selector sent to instance 0x8128eb0'
It looks like your controller class (the target of the button action) is being released before the button fires. The button is likely retained by its superview.
You need to do something to keep the controller class alive (some other instance needs to hold a strong reference to it) for the whole time the button is on display.
I have got the same issue but it wasn't a reference issue. The log 'Unknown class MyViewController in Interface Builder file.' helps me a lot.
I have solved this issue with the answer : Xcode 6 Strange Bug: Unknown class in Interface Builder file
To resolve this issue, be sure the module associated to your view is correctly set :
If you see Module None, there is the issue
Go on Module and just tap enter to see this :
You need to add a : to the selector and change the method
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Instruction Controller";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self
action:#selector(menuButtonClicked:)];
}
-(void) menuButtonClicked:(id)sender {
NSLog(#"menuButtonClicked");
}

FBFriendPickerViewController crashing in FB-IOS SDK3.0

i am working on Facebook SDK3.0 on IOS, i generated Facebook key using developers.facebook.com
my App ID/API Key
165158463618789
Login works fine but while using FBFriendPickerViewController its getting crashing,
I used following code:
FBFriendPickerViewController *friendPicker = [[FBFriendPickerViewController alloc] init];
self.friendPickerController = friendPicker;
[friendPicker loadData];
friendPicker.navigationItem.title = #"Pick Friends";
friendPicker.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:#"Done"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(doneButtonWasPressed:)];
friendPicker.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:#"Cancel"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(cancelButtonWasPressed:)];
[self.navigationController pushViewController:friendPicker animated:YES];
And i am getting crash reason
-[__NSCFDictionary length]: unrecognized selector sent to instance 0x3024d0
2012-08-07 11:13:12.430 IndusPatient[784:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFDictionary length]: unrecognized selector sent to
instance 0x3024d0' * First throw call stack:
(0x321a888f 0x341fe259 0x321aba9b 0x321aa915 0x32105650 0x320f1f19 0x3210e2cd 0x3210d1ad 0x3210e279 0x37a73fb1 0x37a73e8b
0x1a9735 0x1a9bbf 0x31c2fefb 0x31c2efd9 0x31c2e763 0x31bd2f37
0x321071fb 0x33e6baa5 0x33e6b6bd 0x33e6f843 0x33e6f57f 0x33e674b9
0x3217cb1b 0x3217ad57 0x3217b0b1 0x320fe4a5 0x320fe36d 0x31255439
0x31bfdcd5 0xcdd2b 0xcdccc)
terminate called throwing an exception
i was also facing this problem but now i have resolved it.
using following method/code, i resolved issue
In AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Add this line
[FBFriendPickerViewController class];
In your viewController header file add
#property (retain, nonatomic) FBFriendPickerViewController *friendPickerController;
In your viewController implementation file add in a function
if (self.friendPickerController == nil) {
// Create friend picker, and get data loaded into it.
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = #"Pick Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
[self.friendPickerController clearSelection];
[self presentModalViewController:self.friendPickerController animated:YES];
so i have not used navigation controller style programming.

Using UIButtons to open a different .nib

something isn't working right and i can't work out why this isn't working to load my other nib, this currently works
#pragma mark - Flipside View
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)showInfo:(id)sender
{
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
whilst i've done the exact same thing here on the same MainViewController.m and had no success whilst doing it
#pragma mark - News View
- (void)newsViewControllerDidFinish:(NewsViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)showNews:(id)sender
{
NewsViewController *controller = [[NewsViewController alloc] initWithNibName:#"NewsViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
so i think there is something wrong with my header file which looks like this
#import "FlipsideViewController.h"
#import "NewsViewController.h"
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate, NewsViewControllerDelegate>
- (IBAction)showInfo:(id)sender;
- (IBAction)showNews:(id)sender;
#end
I can't work out why it's not working, any help would be appreciated.
Error from output:
This GDB was configured as "x86_64-apple-darwin".Attaching to
process 2147.
2011-07-08 12:24:09.845 Danny[2147:ef03] -[NewsViewController
setDelegate:]: unrecognized selector
sent to instance 0x68a62b0
2011-07-08 12:24:09.847 Danny[2147:ef03] * Terminating app
due to uncaught exception
'NSInvalidArgumentException', reason:
'-[NewsViewController setDelegate:]:
unrecognized selector sent to instance
0x68a62b0'
* First throw call stack:
(0xf8a600 0x112252e 0xf8d550 0xeeb4cf 0xeeb292 0x2a36 0xf8bd78
0x18cc5 0x18c5a 0xbdbd4 0xbe09d
0xbd368 0x3e004 0x3e22d 0x24990
0x181a7 0x1369886 0xf59d11 0xebbc9b
0xeba4b1 0xeb993c 0xeb9868 0x1367fef
0x13680b4 0x160c4 0x2009 0x1f75)
terminate called throwing an exceptionsharedlibrary
apply-load-rules all
Current language: auto; currently objective-c
(gdb)
What is the delegate method for the view controller? Check if the declaration of the delegate method is the same. Make sure you have set the delegates properly
Try this:
- (IBAction)showNews:(id)sender
{
NewsViewController *controller = [[NewsViewController alloc] initWithNibName:#"NewsViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
And in the News View, instead of writing
[self.delegate newsViewControllerDidFinish:self];
you should write:
[self dismissModalViewControllerAnimated:YES];
That should solve your problem. I don't see much point in writing extra delegates, they don't usually give you any advantages (in scenarios like this one), when you can just have a view controller dismiss itself.

Cancel and done button does not work in new contact view

I am trying to integrate new contact control in my app. Here is my code:
- (BOOL) personViewController:(ABPersonViewController*)personView shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue
{
return YES;
}
-(IBAction)addcontact:(id)sender{
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
[self presentModalViewController:navigation animated:YES];
[picker release];
[navigation release];
}
It pops up new contact view but when I click Cancel or Done button nothing happens.
Can anyone help me?
Thanks in advance!
//Make sure your VC is an <ABNewPersonViewControllerDelegate>
-(void) newPersonViewController:(ABNewPersonViewController *)newPersonView
didCompleteWithNewPerson:(ABRecordRef)person {
if (person != nil) //nil = Cancel button clicked
{
//do something
}
//iOS6
[self dismissViewControllerAnimated:YES completion:nil];
}
You need to add methods that should be called when the cancel or done button is tapped and that method should call [self.navigationController dismissModalViewController

Push to another view with UIBarButtonSystemItemAdd

I am trying to edit the add button to push to another view.
But I am receiving an error
-(void)locationAdd:(id)sender{
if([self.parentViewController isKindOfClass:[UINavigationController class]]){
UINavigationController *parent = (UINavigationController *)self.parentViewController;
if ([[parent viewControllers] objectAtIndex:0] == self) {
LocationsAddViewController *alocationAddViewController = [[[LocationsAddViewController alloc] initWithNibName:#"LocationAddView" bundle:[NSBundle mainBundle]] autorelease];
//self.locationAddViewController = alocationAddViewController;
alocationAddViewController.title = #"Toevoegen";
[self.parentViewController pushViewController:alocationAddViewController animated:YES];
}
else if([[parent viewControllers] objectAtIndex:2] == self){
LocationsAddViewController *alocationAddViewController = [[[LocationsAddViewController alloc] initWithNibName:#"LocationAddView" bundle:[NSBundle mainBundle]] autorelease];
alocationAddViewController.title = #"Toevoegen";
[self.parentViewController pushViewController:alocationAddViewController animated:YES];
}
}
}
Because the view can be reached from 2 other views and it has to look different, I have used
if([self.parentViewController isKindOfClass:[UINavigationController class]]){
UINavigationController *parent = (UINavigationController *)self.parentViewController;
if ([[parent viewControllers] objectAtIndex:0] == self) {
to check where it comes from.
The problem is at:
[self.parentViewController pushViewController:alocationAddViewController animated:YES];
I am receiving the error:
+[LocationsTableViewController pushViewController:animated:]: unrecognized selector sent to class 0x23510
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[LocationsTableViewController pushViewController:animated:]: unrecognized selector sent to class 0x23510'
Can someone help me?
What did I do wrong?
Your error indicates that you're trying to call pushViewController:animated: on your LocationsTableViewController class object. This shouldn't be possible given the code you posted. Are you sure you pasted in the exact code that threw the exception? (It's suspicious that your if and else if blocks do the exact same thing.)