FBFriendPickerViewController crashing in FB-IOS SDK3.0 - iphone

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.

Related

Trying to implement Done/Cancel buttons on number keypad, but error is given when textfield is selected in simulator

I have a textfield which is number only. I'm trying to implement a done/cancel buttons on the keypad to get rid of the keypad.
In the simulator when I select the textfield to enter an amount I get the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
[durood keyboardWillShow:]: unrecognized selector sent to instance 0x7644900'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1e4bd 0x1c82bbc 0x1c8294e 0xb914f9 0x1ced0c5 0x1c47efa 0xac5bb2
0x3c5777 0x3be929 0x3c08a2 0x3c0931 0x3c097b 0x3ba117 0x123386 0x122e29 0x2e63c3 0x2e8442
0x2df85a 0x2de99b 0x2e00df 0x2e2d2d 0x2e2cac 0x2daa28 0x47972 0x47e53 0x25d4a 0x17698
0x1beedf9 0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668
0x14ffc 0x209d 0x1fc5 0x1)
libc++abi.dylib: terminate called throwing an exception
Here is the code in my h file:
#import <UIKit/UIKit.h>
int dcounter;
int total;
int enteramount;
#interface durood : UIViewController {
IBOutlet UILabel *dcount;
IBOutlet UILabel *dtotal;
IBOutlet UITextField *numberTextField;
Here is the code in my m file for the extra buttons to be added to the keypad:
[super viewDidLoad];
UIToolbar *numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:#"Cancel"
style:UIBarButtonItemStyleBordered target:self action:#selector(cancelNumberPad)],
[[UIBarButtonItem
alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:#"Apply"
style:UIBarButtonItemStyleDone target:self action:#selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
numberTextField.inputAccessoryView = numberToolbar;
}
-(void)cancelNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = #"";
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}
What am I missing? Any help would be greatly appreciated. The keypad should look like this:
The crash is coming from the fact that durood does not have a method implementation for keyboardWillShow:.
Are you subscribing for notifications, like UIKeyboardWillShowNotification? You likely added a #selector(keyboardWillShow), but didn't actually create the method implementation.

'Application tried to present a nil modal view controller on target' error/crash when trying to open mail composer

I have a simple app, which opens a modal view to send email. Am using Xcode 4.2 and iOS 5, and am testing with iOS Simulator. The app crashes with
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Application tried to present a nil modal view controller on target
.'
when executing the line:
[self presentModalViewController:mailComposer animated:YES];
though I have initialized the object 'mailComposer'.
Class com_FirstViewController.m :
#import "com_FirstViewController.h"
...
#implementation com_FirstViewController
....
....
-(void)showEmailComposer {
Class mailClass = (NSClassFromString(#"MFMailComposeViewController"));
if (mailClass != nil)
{
if ([mailClass canSendMail]) {
NSLog(#"showEmailComposer: Calling displayComposerSheet");
[self displayComposerSheet];
} else {
NSLog(#"showEmailComposer: Calling launchMailAppOnDevice");
[self launchMailAppOnDevice];
}
}
else {
NSLog(#"showEmailComposer: Calling launchMailAppOnDevice");
[self launchMailAppOnDevice];
}
}
#pragma mark -
#pragma mark Compose Mail
-(void) displayComposerSheet {
mailComposer = [[MFMessageComposeViewController alloc] init];
mailComposer.messageComposeDelegate = self;
// Set the mail title
[mailComposer setTitle:#"Mail Title"];
// Set the recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"user#company.com"];
[mailComposer setRecipients:toRecipients];
// EMail Body
NSString *mailBody = #"This is the mail body";
[mailComposer setBody:mailBody];
NSLog(#"present the modal view ctlr");
[self presentModalViewController:mailComposer animated:YES];
}
...
...
Any pointers please?
I have also encountered a similar problem. I allocated an instance of MFMailComposeViewController and tried to present it modally. I also got an exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target
This was because the Mail option was disabled in the settings of the iPhone. It can be the case also when no mail account is set up in the device. So the MFMailCompseViewController instance will be nil and presenting it modally will cause the crash.
I used the canSendMail method of the MFMailComposeViewController to get around this issue.
Class mailClass = (NSClassFromString(#"MFMailComposeViewController"));
if (mailClass != nil) {
MFMailComposeViewController * mailView = [[MFMailComposeViewController alloc] init];
mailView.mailComposeDelegate = self;
//Set the subject
[mailView setSubject:emailSubject];
//Set the mail body
[mailView setMessageBody:emailBody isHTML:YES];
//Display Email Composer
if([mailClass canSendMail]) {
[self.navControl presentModalViewController:mailView animated:YES];
}
}
mailComposer = [[MFMessageComposeViewController alloc] init];
is the source of the problem, in my opinion. There's no way the simulator can send SMS messages, so the initializer method may return NULL. Anyways, sou seem to be wanting to send an email, so I'd say you need to use
mailComposer = [[MFMailComposeViewController alloc] init];

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

iPhone: "unrecognized selector sent to instance"

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.