Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-24-2010, 07:35 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 3
raustyle is on a distinguished road
Default Another "unrecognized selector sent to instance" Problem

Ok I have an app with a tab bar controller and in one of the tabs, there is a navigation controller.

The tabs work fine, and the navigation controller is there, however when I try to click on the button in the first view to move to another view in the navigation controller, I get:

"unrecognized selector sent to instance 0x5d3ee30"

I've built this app purely off of mixing tutorials and videos alone, and am very new to XCode and IB (as in about a week). I feel like I'm so close but need to wrap up some loose ends.

Here's my code:

- DGBankViewController.h

Code:
#import <UIKit/UIKit.h>

#import "DGBankViewController2.h";

@interface DGBankViewController : UIViewController {

  IBOutlet DGBankViewController2 *dgBankViewController2;
  
}

@property (nonatomic, retain) DGBankViewController2 *dgBankViewController2;

-(IBAction)PressMe:(id) sender;


@end


- DGBankViewController.m

Code:
#import "DGBankViewController.h"
#import "DGBankViewController2.h"


@implementation DGBankViewController

@synthesize dgBankViewController2;



- (void)viewDidLoad {
    [super viewDidLoad];
  self.title = @"First View";
}

-(IBAction)PressMe:(id) sender

{
  NSLog(@">Entering DGBankViewController PressMe");
  
  DGBankViewController2 * temp = [[DGBankViewController2 alloc] init];
  [self setDGBankViewController2:temp];
  [temp release];
  
  [[self navigationController] pushViewController:dgBankViewController2 animated:YES];
  
  
  NSLog(@">Finishing DGBankViewController PressMe");
}

- bankAppDelegate.h

Code:
#import <UIKit/UIKit.h>


@interface bankAppDelegate : NSObject {
    IBOutlet UIWindow *window;
  
	//tab bar controller
  IBOutlet UITabBarController *rootController;
  
	//navigation controller
  IBOutlet UINavigationController *dgBankNavigationController;
  
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *rootController;
@property (nonatomic, retain) IBOutlet UINavigationController *dgBankNavigationController;

- bankAppDelegate.m

Code:
#import "bankAppDelegate.h"

@implementation bankAppDelegate

@synthesize window;

//tab bar controller
@synthesize rootController;

//navigation controller
@synthesize dgBankNavigationController;



#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // Override point for customization after application launch.
	[window addSubview:rootController.view];
  [window addSubview:dgBankNavigationController.view];
    [window makeKeyAndVisible];
	
	return YES;
}
Any help would be much much appreciated, and I appreciate the time that anyone takes to look this over, thank you.
raustyle is offline   Reply With Quote
Old 08-24-2010, 07:39 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 66
hatembr is on a distinguished road
Default

i think you should replace

[self setDGBankViewController2:temp];

by

[self setDgBankViewController2:temp];
hatembr is offline   Reply With Quote
Old 08-24-2010, 07:46 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 3
raustyle is on a distinguished road
Default

Quote:
Originally Posted by hatembr View Post
i think you should replace

[self setDGBankViewController2:temp];

by

[self setDgBankViewController2:temp];


Oh my god! Are you kidding me.. It works!

That's all it was.. can you tell me why, when I don't use "DgBankViewController" at all?

And also, thank you so much! It's greatly appreciated and probably saved me hours of trying to find a solution.
raustyle is offline   Reply With Quote
Old 08-24-2010, 07:59 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by raustyle View Post
Oh my god! Are you kidding me.. It works!

That's all it was.. can you tell me why, when I don't use "DgBankViewController" at all?

And also, thank you so much! It's greatly appreciated and probably saved me hours of trying to find a solution.
The reason is it's a naming convention thing. When you say @synthesize dgBankController2, the synthesizes a setter named setDgBankController2. The first letter of the property is turned to upper case when the "set" is placed before it. So when you tried to send the selector "setDGBankController2", you were referring to a method that does not exist.

You could make things a little clearer by a better choice of names.
RLScott is offline   Reply With Quote
Old 08-24-2010, 07:59 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 66
hatembr is on a distinguished road
Default

well you called your member variable "dgBankViewController2" with small "dg"
so your setter will be automatically called "setDgBankViewController2" with just a capital D.

I just noticed it when reading your code, and thought the IBAction was being sent that controller that has never been set

glad it works for u now
hatembr is offline   Reply With Quote
Old 08-24-2010, 08:02 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

The reason is that you are asking for a property with a setter and getter by using the @property and @sythesize.

Code:
@property (nonatomic, retain) DGBankViewController2 *dgBankViewController2;
...
@synthesize dgBankViewController2;
To cut a long story short, this makes a method (an invisible one) called:

Code:
setDgBankViewController2:(DGBankViewController2*)bankViewControllerIn;
It uses the variable name you supplied but adds the word 'set' to it and also capitalises the first letter of your variable so it sticks to camelCase rules. It will also create a getter (again, an invisible one) for you that simply takes the name of your variable.

Code:
-(DBBankViewController2*)dgBankViewController2;
These can be customised and there is really a lot more to this. Words to look up if you want more info are @synthesize, getter, setter and camelCase.

Well done on finding the fix Hatembr, just thought I'd add a little info. I could understand that to someone new to ObjectiveC (even experienced in other languages) this would look like some crazy magic.
__________________
Justinmichael is offline   Reply With Quote
Old 08-24-2010, 08:18 AM   #7 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 66
hatembr is on a distinguished road
Default

I'm surprised I found the fix so quickly I'm also a beginner in iphone dev and obj-C. I couldn't explain it as well as you did Justinmichael
hatembr is offline   Reply With Quote
Old 08-24-2010, 08:20 AM   #8 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 3
raustyle is on a distinguished road
Default

thanks for the replies.. had no idea it was automatically changing letters on me.. now i know..
raustyle is offline   Reply With Quote
Reply

Bookmarks

Tags
instance, iphone, sdk, selector, unrecognized

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 343
7 members and 336 guests
dre, freewind, hain, HemiMG, lendo, Newbie123, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:58 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0