Reputation: 167
this problem's been solved, thanks for your help
So I'm trying to teach myself xcode for programming iphone/ipod apps by writing an app and looking up what I need to know as I need to know it. This website has probably been the biggest help but this time I haven't been able to find an answer to my problem, probably because it's too simple for anyone who has a book to have asked.
I'm trying to create an app that will draw ten cards at random from a deck of 25. I made a class called Dealer that has all of the cards and an array that holds a reference to each of them as member data, as well as a method that returns a card from the array and removes it. here's my code for the method
- (NSString *)drawDominion
{
//some code here
NSString *current = [dominionDeck objectAtIndex:i];
//more irrelevant code
return current;
}
Then in an action method for my View Controller I created an object of my class and tried calling drawDominion but it's giving me the error "Receiver type 'Dealer' for instance message does not declare a method with selector 'drawDominion'
- (IBAction) Dominion
{
Dealer *deal = [[Dealer alloc] init];
NSString *testStr = [deal drawDominion];
}
here's the code where I tried calling drawDominion. I have no idea what I'm doing wrong here, I just picked up xcode yesterday and it's been an uphill battle since then. thanks for any help you can offer.
in answer to some of your replys: Well I didn't make a Dealer.h but I kinda piggy-backed the interface for it in the existing viewController.h could that be causing my problem? it starts after the @end for the class already defined in there and it looks like this.
@interface Dealer : NSObject
-(NSString *) drawDominion:(NSString**)array;
-(NSString *) drawIntrigue:(NSString**)array;
-(NSString *) drawBoth:(NSString**)array;
@end
also I guess I forgot to put the instance variables in the .h but the compiler doesn't seem to be complaining about that. should I put them in there anyway?
Upvotes: 2
Views: 1592
Reputation: 84182
Have you added the prototype for the drawDominion method to Dealer.h ? You should have something like
@interface Dealer : NSObject {
// instance variables here
}
-(NSString*)drawDominion;
@end
In Dealer.h Then when you #import "Dealer.h" the compiler knows that a Dealer will have a drawDominion method.
Upvotes: 1