从另一个对象调用方法

时间:2013-09-09 23:17:07

标签: objective-c

以下示例代码。基本上,在下面的代码中,Game创建了一组名为DragView的对象。触发touchesBegin时,从这些DragView对象中,我需要它回调游戏中的adjustScore方法来调整分数。

@interface Game : UIViewController
{
}
@end

@Implementation Game

DragView *dragger;

- (void)loadView
{
dragger = [[DragView alloc] initWithFrame:dragRect];  
    //simplified...code actually makes lots of these
}

+ (void) adjustScore
 {
NSLog(@"This is called from within DragView");
//does some more stuff…
}


@end


@interface DragView : UIImageView
{
CGPoint startLocation;
}
@end

@implementation DragView

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{   
NSLog(@"Touched");

///// help needed here to call "adjustScore" in Game above /////

} 

1 个答案:

答案 0 :(得分:0)

adjustScore是一种类方法。只需使用:

[Game adjustScore];