Exception while setting property in subclass of MKMapView - iphone

I got a strange error. After I installed my test app in release mode I got an error:
[SomeMapView setRotateEnabled:]: unrecognized selector sent to instance 0x1c58ac40
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SomeMapView setRotateEnabled:]: unrecognized selector sent to instance 0x1c58ac40'
The Mapview was initialized and in the init method I was trying to deactivate the rotation. In the debugging mode it worked fine.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setRotateEnabled:FALSE];
[self initDelegate];
}
return self;
}
Maybe someone knows what's going on? Thanks in advance.

It was a problem in the iOS version. RotateEnabled in available only in iOS7 like Suresh point out. I had to check if the property was there (or check if it has iOS7) like
if ([self respondsToSelector:NSSelectorFromString(elementName)])
{
[self setValue:elementInnerText forKey:elementName];
}

Related

GKLeaderboard in SpriteKit?

How can I use a GKLeaderboard in SpriteKit ?
When I try to present a Leaderboard a got this issue.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setShowsFPS:]: unrecognized selector sent to instance 0x17017fb00'
First throw call stack:
(0x18df0ef50 0x19a4181fc 0x18df13c04 0x18df11930 0x18de315dc 0x100069e00 0x190ed8670 0x190ed83f4 0x190fccd08 0x18df13700 0x18de2ceec 0x1911d5ee4 0x18ed278dc 0x18df13700 0x18de2ceec 0x19a9f0014 0x19a9effd4 0x19a9f31dc 0x18decec2c 0x18deccf6c 0x18de0dc20 0x193af5c0c 0x190f3efdc 0x1000dcb34 0x19aa0baa0)
libc++abi.dylib: terminating with uncaught exception of type NSException**
My Method to show the leaderboard:
-(void) showLeader
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController:leaderboardController animated:YES];
}
}
Thanks in advance!
presentModalViewController was deprecated in iOS 6. GKLeaderbardViewController is deprecated in iOS 7.
You an refer to this:
What should I use instead of deprecated GKLeaderboardViewController in iOS7?

How to find what kind of parameters is required for undocumented version of handleGesture selector (for UIWebView)?

I have added a custom popup menu to UIWebView instance:
- (void)viewDidLoad
{
UILongPressGestureRecognizer* gesture = [[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:#selector(handleGesture::)] autorelease];
}
- (void)handleGesture
{
}
- (void)handleGesture:(UIGestureRecognizer*)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
[gestureRecognizer.view becomeFirstResponder];
UIMenuController* mc = [UIMenuController sharedMenuController];
[mc setTargetRect: gestureRecognizer.view.frame inView: gestureRecognizer.view.superview];
[mc setMenuVisible: YES animated: YES];
}
And it works! Until I focus textarea (CodeMirror editor) on a webpage. At this case I have the following exception:
-[FirstViewController handleGesture::]: unrecognized selector sent to instance 0x20369c00
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FirstViewController handleGesture::]: unrecognized selector sent to instance 0x20369c00'
*** First throw call stack:
(0x3608c2a3 0x3439c97f 0x3608fe07 0x3608e531 0x35fe5f68 0x3747ad31 0x374423dd 0x3762f479 0x37366837 0x3736529b 0x360616cd 0x3605f9c1 0x3605fd17 0x35fd2ebd 0x35fd2d49 0x3650f2eb 0x373b1301 0x140bb 0x14060)
libc++abi.dylib: terminate called throwing an exception
(lldb)
I think it's required to implement undocumented version of handleGesture selector with exotic parameters. Is it right? How to find what kind of parameters is required?
The correct code:
initWithTarget:self action:#selector(handleGesture:)] autorelease];

error after change rootviewcontroller +[NSNotificationCenter dictationViewClass]

I get the following error after I change the rootViewControler of my UIWindow.
2012-10-16 15:12:35.653 repdocApp[22898:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSNotificationCenter dictationViewClass]: unrecognized selector sent to class 0x1d63914'
The strange thing is, it only occurs if I have a line in my code which will never be executed at this time.
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
AppDelegate *app = (AppDelegate *) [[UIApplication sharedApplication] delegate];
OverviewModel *model = [self.dataArray objectAtIndex:indexPath.row];
if (model.modelType == ModelTypeCatalog)
{
NSLog(#"HERE");
if (app.window.rootViewController == app.catalogViewController)
{
return;
}
// with this return no error but this branch is never executed
// return;
[UIView transitionFromView:app.window.rootViewController.view
toView:app.catalogViewController.view
duration:0.45f
options:UIViewAnimationOptionTransitionCrossDissolve
completion:^(BOOL finished){
app.window.rootViewController = app.catalogViewController;
}];
}
else
{
if (app.window.rootViewController == app.catalogViewController)
{
[app.navigationPopoverController dismissPopoverAnimated:NO];
[UIView transitionFromView:app.window.rootViewController.view
toView:app.splitViewController.view
duration:0.45f
options:UIViewAnimationOptionTransitionCrossDissolve
completion:^(BOOL finished){
app.window.rootViewController = app.splitViewController;
}];
}
}
}
I search the whole internet but I found nothing about +[NSNotificationCenter dictationViewClass] or what this can be.
EDIT:
I notice now, it only happens if I change the rootViewController in a transition, if I do it directly no error happens.
Your Error Log is 2012-10-16 15:12:35.653 repdocApp[22898:c07] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSNotificationCenter dictationViewClass]: unrecognized selector sent to class 0x1d63914
You are calling wrong method .dictationViewClass does not exist in ios.
It's Simply mean you are trying to call a methods which is not exist for Corresponding Class (NSNotificationCenter).
You should Change set Notification as below
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(yourMethodWantToExcute:) name:#"NSNotificationName" object:nil];
I hope It'll be helpful to You.
unrecognized selector sent to class means that there is no such method defined for this class. Try:
Delete the line and try if it works.
Look for a category withn your sources if it contains this method
Write your own blank method with the same name
Try to figure ouy what this method meant to do and implement it
Its not a real answer on this but the same error happens on different actions again regardless of an animation.
The problem seems to be the change of the rootviewcontroller, I replace that with a hidden tabbarcontroller and switch between the tabs and the problem is gone.

How to rectify the crash related to iAd in my application

I have integrated iAd in my application and i am executiong it in my simulator. I kept the target iOS 4.1. But some times I am getting the error:
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString bannerViewDidLoadAd:]: unrecognized selector sent to instance 0x6451cd0' " and the application will be quit. What i have to do.
I statically added the ADBannerView in interface builder and used the delegate methods like this:
#pragma mark ADBannerViewDelegate
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
Class classAdBannerView = NSClassFromString(#"ADBannerView");
if(classAdBannerView!= nil)
iAdView2.hidden = NO;
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
Class classAdBannerView = NSClassFromString(#"ADBannerView");
if(classAdBannerView!= nil)
iAdView2.hidden = YES;
}
If any one know the solution please help me.
Exception:
NSInvalidArgumentException', reason:
'-[NSCFString bannerViewDidLoadAd:]: unrecognized selector sent to instance 0x6451cd0' "
Suggests that your delegate object going out of scope. It may be because you have created it in auto-release pool or releasing it somewhere. You will need to retain it.
Thanks

delegate method throws runtime "unrecognized selector" error when switching back from one UIViewController to the main View Controller

Ok, I've spend like half day on this and it's killing me.
So I've got 3 view controllers transitioning from one another, something like this:
I call the UploadDecisionViewController after destroying the previous View Controller:
[self dismissModalViewControllerAnimated:YES];
[self performSelector:#selector(showUDModalView) withObject:nil afterDelay:0.5];
In my showUDModalView method:
- (void)showUDModalView
{
UploadDecisionViewController *udcontroller = [[UploadDecisionViewController alloc] initWithNibName:#"UploadDecisionViewController" bundle:nil];
udcontroller.delegate = self;
[self presentModalViewController:udcontroller animated:YES];
[udcontroller release];
}
The UploadDecisionViewController shows up no problem. The UploadDecisionViewController has a button, which when clicked I want it to transition to the FileUploadViewController. I setup a UploadDecisionDelegate, threw a method in there to handle the button clicking:
Inside UploadDecisionDelegate protocol (UploadDecisionViewController.h):
#protocol UploadDecisionDelegate
//let UOnliveViewController know that a button was selected
- (void)UploadDecisionViewController:(UploadDecisionViewController *)controller madeChoice:(NSString *)whichDirection;
#end
Then inside my IBAction method when the button is clicked, I have this:
- (IBAction)decisionSelected:(id)sender
{
[delegate UploadDecisionViewController:self madeChoice:#"upload"];//crashing at this line
}
When I run this, at this line above it is throwing a runtime exception:
2010-06-09 12:48:59.561 UOnlive[4735:207] *** -[UIView UploadDecisionViewController:madeChoice:]: unrecognized selector sent to instance 0x3b65420
2010-06-09 12:48:59.562 UOnlive[4735:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView UploadDecisionViewController:madeChoice:]: unrecognized selector sent to instance 0x3b65420'
2010-06-09 12:48:59.563 UOnlive[4735:207] Stack: (
33502299,
2495698185,
33884219,
33453686,
33306306,
20618,
2982917,
3390286,
3399023,
3394235,
3087839,
2996168,
3022945,
40156505,
33287040,
33283144,
40150549,
40150746,
3026863,
11700,
11554
)
Let me throw in the delegate method implemented also:
- (void)UploadDecisionViewController:(UploadDecisionViewController *)controller madeChoice:(NSString *)whichDirection
{
NSLog(#"it got to here 245");
[self dismissModalViewControllerAnimated:YES];
if (yesOrNo) {
//open up the FileUploadViewController and proceed to upload
[self performSelector:#selector(showFUModalView) withObject:nil afterDelay:0.5];
}
}
Can someone tell me what the heck is going on? Thanks a bunch for the help...
The error says that you are trying to call the UploadDecisionViewController method on UIView.
My bet is that you set some view to the delegate instead of view controller.
Where the showUDModalView method is located?
Maybe you set the delegate in some additional places?
Your code is to lengthy and I dont want to go through this but just an advice, you can c if your object can/cannot perform a selector with this kind of statement:
if([myObj respondsToSelector:#selector(myFunc)])
{
//do something
}
else{
//do something else
}