-[announceViewController xCJSONDidBeginLoadingJSONData]: unrecognized selector sent to instance 0x7faa01504d50 - ios

I have got this problem cause the app crash:
The probelm start when the app launch when I add the new view to handle 2 uiimages with two buttons
gameApp[5963:1756169] -[announceViewController xCJSONDidBeginLoadingJSONData]: unrecognized selector sent to instance 0x7faa01504d50
2014-11-03 09:16:01.386 gameApp[5963:1756169] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[announceViewController xCJSONDidBeginLoadingJSONData]: unrecognized selector sent to instance 0x7faa01504d50'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107fe9f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000107c82bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000107ff104d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000107f4908f ___forwarding___ + 495
4 CoreFoundation 0x0000000107f48e18 _CF_forwarding_prep_0 + 120
5 gameApp 0x0000000103d75462 -[XCJSONLoader startLoadFrom:] + 66
6 gameApp 0x0000000103d75de3 -[announceViewController setUpJSON] + 259
7 gameApp 0x0000000103d75c99 -[announceViewController viewDidLoad] + 73
8 UIKit 0x0000000106402a90 -[UIViewController loadViewIfRequired] + 738
9 UIKit 0x0000000106402c8e -[UIViewController view] + 27
10 UIKit 0x0000000106321ca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x0000000106322041 -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x000000010632e72c -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x00000001062d9061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
14 UIKit 0x00000001062dbd2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
15 UIKit 0x00000001062dabf2 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x000000010dfa62a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17 CoreFoundation 0x0000000107f1f53c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x0000000107f15285 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x0000000107f15045 __CFRunLoopRun + 2389
20 CoreFoundation 0x0000000107f14486 CFRunLoopRunSpecific + 470
21 UIKit 0x00000001062da669 -[UIApplication _run] + 413
22 UIKit 0x00000001062dd420 UIApplicationMain + 1282
23 gameApp 0x0000000103d78913 main + 115
24 libdyld.dylib 0x0000000108c17145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
and here is the h file :
#import <UIKit/UIKit.h>
#import "XCJSONLoader.h"
#interface announceViewController : UIViewController <XCJSONLoaderDelegate>
#property (strong,nonatomic) XCJSONLoader *jsonLoader;
#property (weak, nonatomic) IBOutlet UIImageView *anImageView;
#property (weak, nonatomic) IBOutlet UIImageView *spImageView;
- (IBAction)anButton:(id)sender;
- (IBAction)spButton:(id)sender;
#end
and this is the .m file
#interface announceViewController () {
NSMutableArray *JSONData;
}
#end
#implementation announceViewController
#synthesize jsonLoader,anImageView,spImageView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setUpJSON];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (void) setUpJSON
{
jsonLoader = [[XCJSONLoader alloc] init];
[jsonLoader setDelegate:self];
NSString *JSONLink = [NSString stringWithFormat:#"http://ya-techno.com/gameApp/anData.php"]; // Your URL goes here
[jsonLoader startLoadFrom:JSONLink];
}
- (void)xCJSONDidFinishLoadingJSONData
{
JSONData = [jsonLoader getJSONData];
}
- (IBAction)anButton:(id)sender {
JSONData = [jsonLoader getJSONData];
NSString *anButtonString = [NSString stringWithFormat:#"%#", [[JSONData objectAtIndex:0] objectForKey:#"anButton"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:anButtonString]];
}
- (IBAction)spButton:(id)sender {
}
#end
I could not find the problem for this one. Any help

Read the error. It says you haven't implemented the xCJSONDidBeginLoadingJSONData method. And you haven't. You do have the xCJSONDidFinishLoadingJSONData method but not the xCJSONDidBeginLoadingJSONData method.
Add the xCJSONDidBeginLoadingJSONData method to your announceViewController class to fix the problem.
BTW - standard naming conventions state that class names should being with uppercase letters. Method and variable names begin with lowercase letters.

Related

iOS this class is not key value coding-compliant for the key label

So I'm new to iOS programming and I've run into a problem.
I created a new view controller, and clicked the checkmark to auto make a .xib file for it. In the xib file I put a label, that I want to fade in. So I tried linking it to my custom view controller, and keep crashing with 'this class is not key value coding-compliant for the key login1'. Login1 being the name of the UILabel I imported. Here's the header file for RootView:
#interface RootViewController : UIViewController {
PlayerStatViewController *playerStatViewController;
NSString *viewName;
}
#property (weak, nonatomic) IBOutlet UILabel *login1;
#property (nonatomic, retain) PlayerStatViewController *playerStatViewController;
#property (nonatomic, retain) NSString *viewName;
-(IBAction)switchPage:(id)sender:(NSString *)toSwitch;
-(void) animateButton;
#end
And the .m file:
#import "RootViewController.h"
#import "FileUtils.h"
#interface RootViewController ()
#end
#implementation RootViewController
#synthesize playerStatViewController;
#synthesize viewName;
#synthesize login1;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
self.viewName = #"Boot";
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* fpath = [NSString stringWithFormat:#"%#%#", getDefPath(), #"/config.txt"];
self.login1.text = loadfile(#"serverName", fpath);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(IBAction)switchPage:(id)sender :(NSString *)toSwitch {
if([toSwitch isEqualToString:(#"PlayerStat")]) {
if(self.playerStatViewController == nil) {
PlayerStatViewController *playerStatView = [[PlayerStatViewController alloc]
initWithNibName:(#"PlayerStat") bundle:[NSBundle mainBundle]];
self.playerStatViewController = playerStatView;
}
[self.navigationController pushViewController:self.playerStatViewController animated:YES];
}else if([toSwitch isEqualToString:(#"Boot")]) {
[self.navigationController pushViewController:self animated:YES];
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self performSelector:#selector(animateButton) withObject:nil afterDelay:0.1f];
}
- (void)animateButton {
self.login1.alpha = 0;
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn
animations:^{ self.login1.alpha = 1;}
completion:nil];
}
#end
How I load the Xib (if it matters):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *viewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
[self.window setRootViewController:viewController];
[window makeKeyAndVisible];
return YES;
}
Project being built for iPhone only.
In the Xib, yes the custom view controller is set as the file owner. There is no mispointing values (exclamation points in inspection manager).
edit:
crash log:
2014-08-06 06:02:12.887 TrinityApi[5761:60b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x8c781d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key login1.'
*** First throw call stack:
(
0 CoreFoundation 0x017ee1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0156d8e5 objc_exception_throw + 44
2 CoreFoundation 0x0187dfe1 -[NSException raise] + 17
3 Foundation 0x0122dd9e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x0119a1d7 _NSSetUsingKeyValueSetter + 88
5 Foundation 0x01199731 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x011fbb0a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x004e41f4 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x0157f7de -[NSObject performSelector:] + 62
9 CoreFoundation 0x017e976a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x004e2d4d -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x004e4ada -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 165
12 UIKit 0x0022d61b -[UIApplication _loadMainNibFileNamed:bundle:] + 58
13 UIKit 0x0022d949 -[UIApplication _loadMainInterfaceFile] + 245
14 UIKit 0x0022c54e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 543
15 UIKit 0x00240f92 -[UIApplication handleEvent:withNewEvent:] + 3517
16 UIKit 0x00241555 -[UIApplication sendEvent:] + 85
17 UIKit 0x0022e250 _UIApplicationHandleEvent + 683
18 GraphicsServices 0x037e3f02 _PurpleEventCallback + 776
19 GraphicsServices 0x037e3a0d PurpleEventCallback + 46
20 CoreFoundation 0x01769ca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
21 CoreFoundation 0x017699db __CFRunLoopDoSource1 + 523
22 CoreFoundation 0x0179468c __CFRunLoopRun + 2156
23 CoreFoundation 0x017939d3 CFRunLoopRunSpecific + 467
24 CoreFoundation 0x017937eb CFRunLoopRunInMode + 123
25 UIKit 0x0022bd9c -[UIApplication _run] + 840
26 UIKit 0x0022df9b UIApplicationMain + 1225
27 TrinityApi 0x00002a9d main + 141
28 libdyld.dylib 0x01e35701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
EDIT: Just randomly started to work
"class is not key value coding-compliant " means You had assigned an outlet to our label at first and had connected it in our xib, but then you have deleted the outlet and the xib is still containing a reference to the outlet which is no longer present, You need to remove this reference from your xib.
Goto your XIB file and right click on Files Owner, you may find a label with a yellow mark on it, just remove the outlet to which its connected to, clean and run your program once again

UIPopover Error:'-[UIPopoverController init] is not a valid initializer. You must call -[UIPopoverController initWithContentViewController:].'

I'm trying to create a UIPopover, yet I can't. Here is the code I am using:
iAPAddOn.h:
#import "CodeaAddon.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "InAppPurchasePopoverViewController.h"
id IAPAddOnInstance;
#interface IAPAddOn : UIPopoverController<CodeaAddon>
{
UIPopoverController* popover;
}
#property (weak, nonatomic) CodeaViewController *codeaViewController;
#end
iApAddOn.m:
#import "lua.h"
#import "IAPAddOn.h"
#implementation IAPAddOn
#pragma mark - Initialisation
- (id)init
{
self = [super init];
if (self)
{
IAPAddOnInstance = self;
InAppPurchasePopoverViewController* popoverController = [[InAppPurchasePopoverViewController alloc] initWithNibName:#"InAppPurchasePopover" bundle:nil];
popover = [[UIPopoverController alloc] initWithContentViewController:popoverController];
}
return self;
}
#pragma mark - CodeaAddon Delegate
- (void) codea:(CodeaViewController*)controller didCreateLuaState:(struct lua_State*)L
{
NSLog(#"IAPAddOn Registering Functions");
lua_register(L, "showIAPPopOver", showIAPPopOver);
self.codeaViewController = controller;
}
#pragma mark - Init
static int showIAPPopOver(struct lua_State *state) {
[IAPAddOnInstance showIAPPopOverAction];
return 0;
}
- (void) showIAPPopOverAction {
[popover presentPopoverFromRect:CGRectMake(100, 100, 100, 100) inView:self.codeaViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];
}
#end
It results with a crash on startup and logging this in the console:
2014-02-02 01:44:37.131 StackIt[42088:70b] *** Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController init] is not a valid initializer. You must call -[UIPopoverController initWithContentViewController:].'
*** First throw call stack:
(
0 CoreFoundation 0x037725e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x031878b6 objc_exception_throw + 44
2 CoreFoundation 0x037723bb +[NSException raise:format:] + 139
3 UIKit 0x00a86712 -[UIPopoverController init] + 59
4 StackIt 0x00006fae -[IAPAddOn init] + 78
5 StackIt 0x00002c19 -[AppDelegate application:didFinishLaunchingWithOptions:] + 617
6 UIKit 0x004b2355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
7 UIKit 0x004b2b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
8 UIKit 0x004b73a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
9 UIKit 0x004cb87c -[UIApplication handleEvent:withNewEvent:] + 3447
10 UIKit 0x004cbde9 -[UIApplication sendEvent:] + 85
11 UIKit 0x004b9025 _UIApplicationHandleEvent + 736
12 GraphicsServices 0x04d342f6 _PurpleEventCallback + 776
13 GraphicsServices 0x04d33e01 PurpleEventCallback + 46
14 CoreFoundation 0x036edd65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
15 CoreFoundation 0x036eda9b __CFRunLoopDoSource1 + 523
16 CoreFoundation 0x0371877c __CFRunLoopRun + 2156
17 CoreFoundation 0x03717ac3 CFRunLoopRunSpecific + 467
18 CoreFoundation 0x037178db CFRunLoopRunInMode + 123
19 UIKit 0x004b6add -[UIApplication _run] + 840
20 UIKit 0x004b8d3b UIApplicationMain + 1225
21 StackIt 0x0000297d main + 141
22 libdyld.dylib 0x03ce770d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Any help would be wonderful.
Thank you!
Looks like you should have:
- (id)init
{
InAppPurchasePopoverViewController* purchaseController = [[InAppPurchasePopoverViewController alloc] initWithNibName:#"InAppPurchasePopover" bundle:nil];
self = [super initWithContentViewController:purchaseController];
if (self)
{
}
return self;
}
Because currently your class isn't respecting it's superclass requirements and is creating an additional popover controller which is not used properly. Everywhere you use popover should really be using self.

iOS/Facebook Login error: this class is not key value coding-compliant for the key

I'm just trying to build a Facebook Login page for my iOS app, but it keeps breaking when IBOutlet in my LoginViewController tries to connect to a UIActivityIndicatorView. Here is the error that I get:
2013-12-10 00:29:11.062 uConnect[2254:70b] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key loader.'
Here is my interface
#interface UConnectLoginViewController : UIViewController
-(void)loginFailed;
#property (strong, nonatomic) IBOutlet UIActivityIndicatorView* loader;
#end
here is my implementation
#interface UConnectLoginViewController ()
-(IBAction)performLogin:(id)sender;
#end
#implementation UConnectLoginViewController
#synthesize loader;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)performLogin:(id)sender
{
[self.loader startAnimating];
UConnectAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate openSession];
}
-(void)loginFailed
{
[self.loader stopAnimating];
}
#end
In the xib file I already hooked up the Outlet to the view.
EDIT:
Here is the full console error log:
2013-12-10 18:02:13.830 uConnect[3596:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UConnectLoginViewController 0x8a8c4a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key spinner.'
*** First throw call stack:
(
0 CoreFoundation 0x017b85e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0153b8b6 objc_exception_throw + 44
2 CoreFoundation 0x018486a1 -[NSException raise] + 17
3 Foundation 0x011fc9ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x01168cfb _NSSetUsingKeyValueSetter + 88
5 Foundation 0x01168253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x011ca70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x0054ba15 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x0154d7d2 -[NSObject performSelector:] + 62
9 CoreFoundation 0x017b3b6a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x0054a56e -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x003bc605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
12 UIKit 0x003bcdad -[UIViewController loadView] + 302
13 UIKit 0x003bd0ae -[UIViewController loadViewIfRequired] + 78
14 UIKit 0x003bd5b4 -[UIViewController view] + 35
15 UIKit 0x003ccab9 -[UIViewController shouldAutorotate] + 36
16 UIKit 0x003cce01 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 297
17 UIKit 0x006515e5 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2330
18 UIKit 0x003c90fc -[UIViewController presentViewController:withTransition:completion:] + 6433
19 UIKit 0x003c961f -[UIViewController presentViewController:animated:completion:] + 130
20 uConnect 0x00002c7a -[UConnectAppDelegate showLoginView] + 218
21 uConnect 0x000029b7 -[UConnectAppDelegate application:didFinishLaunchingWithOptions:] + 647
22 UIKit 0x002a3355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
23 UIKit 0x002a3b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
24 UIKit 0x002a83a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
25 UIKit 0x002bc87c -[UIApplication handleEvent:withNewEvent:] + 3447
26 UIKit 0x002bcde9 -[UIApplication sendEvent:] + 85
27 UIKit 0x002aa025 _UIApplicationHandleEvent + 736
28 GraphicsServices 0x0375f2f6 _PurpleEventCallback + 776
29 GraphicsServices 0x0375ee01 PurpleEventCallback + 46
30 CoreFoundation 0x01733d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
31 CoreFoundation 0x01733a9b __CFRunLoopDoSource1 + 523
32 CoreFoundation 0x0175e77c __CFRunLoopRun + 2156
33 CoreFoundation 0x0175dac3 CFRunLoopRunSpecific + 467
34 CoreFoundation 0x0175d8db CFRunLoopRunInMode + 123
35 UIKit 0x002a7add -[UIApplication _run] + 840
36 UIKit 0x002a9d3b UIApplicationMain + 1225
37 uConnect 0x000026fd main + 141
38 libdyld.dylib 0x01df670d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The app delegate code mentioned in the output:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch. WE CHECK IF THEY ARE ALREADY LOGGED IN OR NOT.
self.mainViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"UconnectViewController"];
self.navigationController = [[UINavigationController alloc]
initWithRootViewController:self.mainViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
// Open the session
[self openSession];
} else {
//Display login view
[self showLoginView];
}
return YES;
}
Here is the other function.
-(void)showLoginView
{
UIViewController *topViewController = [self.navigationController topViewController];
UIViewController *presentedViewController = [topViewController presentedViewController];
//-If login screen is not displayed display it.
//-If the login screen is displayed and we come back here then login failure.
//-Update UI if the second happens
if (![presentedViewController isKindOfClass:[UConnectLoginViewController class]]) {
UConnectLoginViewController* login = [[UConnectLoginViewController alloc] initWithNibName:#"UConnectLoginViewController" bundle:nil];
[topViewController presentViewController:login animated:NO completion:nil];
} else {
UConnectLoginViewController* login = (UConnectLoginViewController*) presentedViewController;
[login loginFailed];
}
}
OK, Maybe the problem is that you forget to put "URL types" in your Info.plist
Open your Info.plist
Add URL Types key (take it from dropdown)
This will add an array of 1 dictionary type item
Select "URL Schemes" array from the dictionary's dropdown
This will add "URL Schemes" array
add a string containing "fb{YourFBAppId}" in "URL Schemes" array
I hope that this will help you4

unrecognized selector from protocol

UPDATE: Issue found, solution found and marked as answer.
Issue is that I use a static method of the superclass to initialize, thus turning it into the superclass instead of subclass.
END UPDATE:
I have a protocol, a class that implements that protocol, and then a class that creates an instance of the protocol'd class that calls the protocol method. I am receiving an "Unrecognized selector sent to instance..." when invoking that protocol method.
Note: I am using ArcGIS for displaying a map, but that should be irrelevant to my problem.
The protocol method (layerName) works later during runtime on another object that implements LayerProtocol.
Example Code:
#protocol LayerProtocol <NSObject>
- (NSString *) layerName;
#end
#interface StreetLayer: AGSTiledMapServiceLayer<LayerProtocol>
#end
#implementation StreetLayer
- (id) init
{
self = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:
[NSURL URLWithString: [NSString stringWithFormat:
#"%#%#",
#"https://server.arcgisonline.com/ArcGIS/",
#"rest/services/World_Street_Map/MapServer"]
]];
return self;
}
- (NSString *) layerName
{
return #"Street Layer";
}
#end
#interface MapContainerViewController: UIViewController
#property (nonatomic) AGSMapView * mapView;
#property (nonatomic) StreetLayer * layer;
#end
#implementation MapContainerViewController
- (void) viewDidLoad
{
_mapView = [[AGSMapView alloc] init];
_layer = [[StreetLayer alloc] init];
[mapView addMapLayer:_layer withName:[_layer layerName]];
}
The error occurs on the access to [_layer layerName]
I feel like I'm missing something really obvious here.
I do know that AGSLayer has an access to the name of the layer, that is irrelevant to the problem.
Additionally, I have used [_layer respondsToSelector:#selector(layerName)] and it fails that check.
STACK TRACE:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AGSTiledMapServiceLayer layerName]: unrecognized selector sent to instance 0xbe7ef90'
* First throw call stack:
(
0 CoreFoundation 0x035105e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x032938b6 objc_exception_throw + 44
2 CoreFoundation 0x035ad903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0350090b ___forwarding___ + 1019
4 CoreFoundation 0x035004ee _CF_forwarding_prep_0 + 14
5 MyProject 0x00061d95 -[MapContainerViewController mapTypeToggled:] + 677
6 libobjc.A.dylib 0x032a5874 -[NSObject performSelector:withObject:withObject:] + 77
7 UIKit 0x01522c8c -[UIApplication sendAction:to:from:forEvent:] + 108
8 UIKit 0x01522c18 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
9 UIKit 0x0161a6d9 -[UIControl sendAction:to:forEvent:] + 66
10 UIKit 0x0161aa9c -[UIControl _sendActionsForEvents:withEvent:] + 577
11 UIKit 0x01619d4b -[UIControl touchesEnded:withEvent:] + 641
12 UIKit 0x015600cd -[UIWindow _sendTouchesForEvent:] + 852
13 UIKit 0x01560d34 -[UIWindow sendEvent:] + 1232
14 UIKit 0x01534a36 -[UIApplication sendEvent:] + 242
15 UIKit 0x0151ed9f _UIApplicationHandleEventQueue + 11421
16 CoreFoundation 0x034998af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
17 CoreFoundation 0x0349923b __CFRunLoopDoSources0 + 235
18 CoreFoundation 0x034b630e __CFRunLoopRun + 910
19 CoreFoundation 0x034b5b33 CFRunLoopRunSpecific + 467
20 CoreFoundation 0x034b594b CFRunLoopRunInMode + 123
21 GraphicsServices 0x051d49d7 GSEventRunModal + 192
22 GraphicsServices 0x051d47fe GSEventRun + 104
23 UIKit 0x0152194b UIApplicationMain + 1225
24 GmcSeeds 0x00073b1d main + 141
25 libdyld.dylib 0x03a7f725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
- (void) mapTypeToggled:(id)sender
{
_streetViewToggled = !_streetViewToggled;
if (_streetViewToggled)
{
// show street view
[_mapView removeMapLayer:_satelliteLayer];
[_mapView insertMapLayer:_streetLayer
withName:[_streetLayer layerName]
atIndex:0];
}
else
{
// show satellite view
[_mapView removeMapLayer:_streetLayer];
[_mapView insertMapLayer:_satelliteLayer
withName:[_satelliteLayer layerName]
atIndex:0];
}
}
One option is to replace this
- (id) init
{
self = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:
[NSURL URLWithString: [NSString stringWithFormat:
#"%#%#",
#"https://server.arcgisonline.com/ArcGIS/",
#"rest/services/World_Street_Map/MapServer"]
]];
return self;
}
with this
- (id) init
{
self = [[self class] tiledMapServiceLayerWithURL:
[NSURL URLWithString: [NSString stringWithFormat:
#"%#%#",
#"https://server.arcgisonline.com/ArcGIS/",
#"rest/services/World_Street_Map/MapServer"]
]];
return self;
}
Better yet you should have a class method for creating a street layer:
#implementation StreetLayer
+ (instancetype)streetLayer
{
return [[self class] tiledMapServiceLayerWithURL:
[NSURL URLWithString: [NSString stringWithFormat:
#"%#%#",
#"https://server.arcgisonline.com/ArcGIS/",
#"rest/services/World_Street_Map/MapServer"]
]];
}
#end

Thread 1: signal SIGABRT error in main

Got this error message in the main function. Am new to debugging this kind of error in Xcode 5, so would appreciate your suggestions about how to approach this kind of error.
Thanks in advance.
Here is the code:
Main:
#import <UIKit/UIKit.h>
#import "BullsEyeAppDelegate.h"
int main(int argc, char * argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([BullsEyeAppDelegate class])); //Thread 1: signal SIGABRT
}
}
BullsEyeViewController.h
#import <UIKit/UIKit.h>
#interface BullsEyeViewController : UIViewController
#property (nonatomic, weak) IBOutlet UISlider *slider;
#property (nonatomic, weak) IBOutlet UILabel *targetLabel;
#property (nonatomic, weak) IBOutlet UILabel *scoreLabel;
#property (nonatomic, weak) IBOutlet UILabel *roundLabel;
-(IBAction)showAlert;
-(IBAction)sliderMoved:(UISlider *)slider;
#end
BullsEyeViewController.m
#import "BullsEyeViewController.h"
#interface BullsEyeViewController ()
#end
#implementation BullsEyeViewController
{
int _currentValue;
int _targetValue;
int _score;
int _round;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self startNewRound];
[self updateLabels];
}
-(void)startNewRound
{
_targetValue = 1 + arc4random_uniform(100);
_currentValue = 50;
self.slider.value = _currentValue;
[self updateLabels];
}
-(void)updateLabels
{
self.targetLabel.text = [NSString stringWithFormat:#"%d", _targetValue];
// Convert the int into a string so that it will fit in the label as an outlet
self.scoreLabel.text = [NSString stringWithFormat:#"%d", _score];
self.roundLabel.text = [NSString stringWithFormat:#"%d", _round];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)showAlert
{
int difference = abs(_currentValue - _targetValue);
int points = 100 - difference;
_score += points;
NSString *message = [NSString stringWithFormat:#"You scored %d points", points];
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Hello World"
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alertView show];
[self startNewRound];
[self updateLabels];
}
-(IBAction)sliderMoved:(UISlider *)slider
{
_currentValue = lroundf(slider.value);
}
#end
Error Trace:
2013-11-19 19:59:12.299 BullsEye[13764:70b] -[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20
2013-11-19 19:59:12.351 BullsEye[13764:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20'
*** First throw call stack:
(
0 CoreFoundation 0x0173a5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bd8b6 objc_exception_throw + 44
2 CoreFoundation 0x017d7903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172a90b ___forwarding___ + 1019
4 CoreFoundation 0x0172a4ee _CF_forwarding_prep_0 + 14
5 Foundation 0x0117d737 _NSSetIntValueForKeyInIvar + 46
6 Foundation 0x010eada3 _NSSetUsingKeyValueSetter + 256
7 Foundation 0x010ea253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
8 Foundation 0x0114c70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
9 UIKit 0x004cda15 -[UIRuntimeOutletConnection connect] + 106
10 libobjc.A.dylib 0x014cf7d2 -[NSObject performSelector:] + 62
11 CoreFoundation 0x01735b6a -[NSArray makeObjectsPerformSelector:] + 314
12 UIKit 0x004cc56e -[UINib instantiateWithOwner:options:] + 1417
13 UIKit 0x0033e605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
14 UIKit 0x0033edad -[UIViewController loadView] + 302
15 UIKit 0x0033f0ae -[UIViewController loadViewIfRequired] + 78
16 UIKit 0x0033f5b4 -[UIViewController view] + 35
17 UIKit 0x002679fd -[UIWindow addRootViewControllerViewIfPossible] + 66
18 UIKit 0x00267d97 -[UIWindow _setHidden:forced:] + 312
19 UIKit 0x0026802d -[UIWindow _orderFrontWithoutMakingKey] + 49
20 UIKit 0x0027289a -[UIWindow makeKeyAndVisible] + 65
21 UIKit 0x00225cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
22 UIKit 0x0022a3a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
23 UIKit 0x0023e87c -[UIApplication handleEvent:withNewEvent:] + 3447
24 UIKit 0x0023ede9 -[UIApplication sendEvent:] + 85
25 UIKit 0x0022c025 _UIApplicationHandleEvent + 736
26 GraphicsServices 0x036e12f6 _PurpleEventCallback + 776
27 GraphicsServices 0x036e0e01 PurpleEventCallback + 46
28 CoreFoundation 0x016b5d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
29 CoreFoundation 0x016b5a9b __CFRunLoopDoSource1 + 523
30 CoreFoundation 0x016e077c __CFRunLoopRun + 2156
31 CoreFoundation 0x016dfac3 CFRunLoopRunSpecific + 467
32 CoreFoundation 0x016df8db CFRunLoopRunInMode + 123
33 UIKit 0x00229add -[UIApplication _run] + 840
34 UIKit 0x0022bd3b UIApplicationMain + 1225
35 BullsEye 0x0000219d main + 141
36 libdyld.dylib 0x01d7870d start + 1
37 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
These 2 lines reveal your error in the error trace:
2013-11-19 19:59:12.299 BullsEye[13764:70b] -[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20
2013-11-19 19:59:12.351 BullsEye[13764:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel intValue]: unrecognized selector sent to instance 0x8a7ef20'
It appears you error isn't caused by the code you posted but where ever you have:
[UILabel intValue];
Wherever you are using the above code, you are trying to get the integer value of a UILabel, when you should be trying to get the integer value of the text property of the UILabel.
So, assuming the name of your label is "myLabel:"
[myLabel.text intValue];

Resources