iPhone: "unrecognized selector sent to instance" - iphone

I try to set two different views into a subview, according to the state of a SegmentSwitcher:
if ([sender selectedSegmentIndex] == gameIndex) {
if (self.gameView.view == nil) {
GameView *gameV = [[UIViewController alloc] initWithNibName:#"GameView" bundle:nil];
self.gameView = gameV;
[gameV release];
}
[tableView.view removeFromSuperview];
[subView insertSubview:gameView.view atIndex:0];
} else {
if (self.tableView.view == nil) {
TableView *tableV = [[UIViewController alloc] initWithNibName:#"TableView" bundle:nil];
self.tableView = tableV;
[tableV release];
}
[tableView.view removeFromSuperview];
[subView insertSubview:tableView.view atIndex:0];
}
TableView extends TableViewController, but I always get the following error when I try to switch to the tableview:
2010-01-06 19:55:00.871 Handball[84675:40b] * -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x3b18360
2010-01-06 19:55:00.873 Handball[84675:40b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x3b18360'
2010-01-06 19:55:00.874 Handball[84675:40b] Stack: (
Any help would be REALLY, REALLY appreciated...

While tableV is declared to be a TableView, it's most likely initialized with a simple UIViewConrtoller, as it appears in your code. Try changing the line to:
TableView *tableV = [[TableView alloc] initWithNibName:#"TableView" bundle:nil];
And TableView should be a subtype of UITableViewController.
By the way, the same should probably happen with GameView as well.

Related

iPad back to previous view terminates the application while works perfectly on iPhone

I tried many ways to show navigation bar but it wont work for me. So I put Back button in secondViewController and it works perfectly for me on iPhone but terminates app on iPad.
- (IBAction)back:(id)sender {
[self.view endEditing:YES];
if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
LuanchViewController* SVC = [[LuanchViewController alloc] initWithNibName:#"LuanchViewController_iPhone" bundle:nil];
[self presentViewController:SVC animated:YES completion:nil];
}
if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[self.view endEditing:YES];
LuanchViewController* SVC = [[LuanchViewController alloc] initWithNibName:#"LuanchViewController_iPhone" bundle:nil];
[self presentViewController:SVC animated:YES completion:nil];
}
[self dismissModalViewControllerAnimated:YES];
}
Error :-
2013-10-16 18:44:42.775 iOS-test-harness[7095:c07] -[ViewController back:]: unrecognized selector sent to instance 0xa2accb0
2013-10-16 18:44:50.193 iOS-test-harness[7095:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController back:]: unrecognized selector sent to instance 0xa2accb0'
*** First throw call stack:
(0x2c18012 0x1e8ce7e 0x2ca34bd 0x2c07bbc 0x2c0794e 0x1ea0705 0xdd42c0 0xdd4258 0xe95021 0xe9557f 0xe946e8 0xe03cef 0xe03f02 0xde1d4a 0xdd3698 0x2e51df9 0x2e51ad0 0x2b8dbf5 0x2b8d962 0x2bbebb6 0x2bbdf44 0x2bbde1b 0x2e507e3 0x2e50668 0xdd0ffc 0x240d 0x2335)
libc++abi.dylib: terminate called throwing an exception
It seems to be that you have a Class ViewController (mostly a superclass of LuanchViewController) and it is call a method back which is not in the implementation.
This looks like an unwind segue action method. If you are using storyboards and you have a different storyboard for iPhone and iPad (which is the default) you probably need to make sure the iPad storyboard has the correct view controller classes set in each scene.

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.

iOS AddressBookUI - 'Shouldn't be trying to show more than one Add to Existing Contact people picker.'

I'm trying add some addressbook functionality to my app, but after tap the second time to the 'Add to existing' button I get this error message.
* Assertion failure in -[ABPersonViewControllerHelper presentPeoplePickerNavigationControllerForAddToContacts:], /SourceCache/AddressBookUI_Sim/AddressBookUI-1118/ABPersonViewControllerHelper.m:2574
2011-10-24 20:41:11.960 locato[4576:11603]
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Shouldn't be trying to show more than one Add to Existing Contact people picker.'
First throw call stack:
(0x152e052 0x16bfd0a 0x14d6a78 0xefd2db 0x9d674 0x152fe72 0xd0eb8 0xc8141 0xb9e2f 0x60471d 0x604952 0xe8c86d 0x1502966 0x1502407 0x14657c0 0x1464db4 0x1464ccb 0x17eb879 0x17eb93e 0x574a9b 0x22d9 0x2255)
terminate called throwing an exception
I have a viewcontroller and a navigationcontroller, and im displaying the addressbook's 'modal' views on the main viewcontroller. (or else im not getting the sliding transition, and this error.). I have overridden these methods:
#implementation UIViewController (cancelButton)
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker;
{
UIResponder *responder = self;
while (responder && ![responder isKindOfClass:[mainViewController class]]) {
responder = [responder nextResponder];
}
[(UIViewController *)responder dismissModalViewControllerAnimated:YES];
}
#end
#implementation UINavigationController (modal)
- (void) presentModalViewController:(UIViewController *)screen animated:(BOOL)animated
{
UIResponder *responder = self;
while (responder && ![responder isKindOfClass:[mainViewController class]]) {
responder = [responder nextResponder];
}
if ([screen isKindOfClass:[ABPeoplePickerNavigationController class]]) {
ABPeoplePickerNavigationController *scr = screen;
scr.peoplePickerDelegate = self;
[scr release];
}
[(UIViewController *)responder presentModalViewController:screen animated:YES];
}
Im hoping to get some clarification on what im not doing right!
thanks,
David
Two things you could change before trying again:
after both while loops, check that responder is not nil before doing dismiss or present a viewcontroller
can't you just assign screen.peoplePickerDelegate = self; instead of using this scr?

Unrecognized selector sent to instance

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)

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