Note that there are some explanatory texts on larger screens.

plurals
  1. POxcode/objective-c Calling instance methods
    text
    copied!<p><strong>this problem's been solved, thanks for your help</strong></p> <p>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.</p> <p>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</p> <pre><code>- (NSString *)drawDominion { //some code here NSString *current = [dominionDeck objectAtIndex:i]; //more irrelevant code return current; } </code></pre> <p>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'</p> <pre><code>- (IBAction) Dominion { Dealer *deal = [[Dealer alloc] init]; NSString *testStr = [deal drawDominion]; } </code></pre> <p>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.</p> <p>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.</p> <pre><code>@interface Dealer : NSObject -(NSString *) drawDominion:(NSString**)array; -(NSString *) drawIntrigue:(NSString**)array; -(NSString *) drawBoth:(NSString**)array; @end </code></pre> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload