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.
因此,我正在尝试通过编写应用程序来编写iphone / ipod应用程序来自学xcode,并查找我需要知道的内容,因为我需要知道它。这个网站可能是最大的帮助,但这次我找不到我的问题的答案,可能是因为对于有书的人来说这太简单了。
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
我正在尝试创建一个应用程序,它将从25个套牌中随机抽取10张牌。我创建了一个名为Dealer的类,其中包含所有卡片和一个数组,其中包含对每个卡片的成员数据的引用,以及作为从数组中返回卡并将其删除的方法。这是我的方法代码
- (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'
然后在我的视图控制器的一个动作方法中,我创建了一个我的类的对象并尝试调用drawDominion,但它给了我错误“接收器类型'经销商'例如消息没有声明一个带有选择器'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.
这是我尝试调用drawDominion的代码。我不知道我在这里做错了什么,我昨天刚拿起xcode,从那时起它就是一场艰苦的战斗。谢谢你尽你所能的帮助。
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.
回答你的一些回复:好吧,我没有制作一个Dealer.h但我有点捎带现有viewController.h中的接口,这可能导致我的问题?它在@end之后开始,已经在那里定义了类,它看起来像这样。
@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?
另外我想我忘了将实例变量放在.h中,但编译器似乎没有抱怨。我应该把它们放在那里吗?
1 个解决方案
#1
1
Have you added the prototype for the drawDominion method to Dealer.h ? You should have something like
您是否已将drawDominion方法的原型添加到Dealer.h中?你应该有类似的东西
@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.
在Dealer.h中当你#import“Dealer.h”时,编译器知道经销商会有drawDominion方法。
#1
1
Have you added the prototype for the drawDominion method to Dealer.h ? You should have something like
您是否已将drawDominion方法的原型添加到Dealer.h中?你应该有类似的东西
@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.
在Dealer.h中当你#import“Dealer.h”时,编译器知道经销商会有drawDominion方法。