以下示例代码。基本上,在下面的代码中,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 /////
}
答案 0 :(得分:0)
adjustScore
是一种类方法。只需使用:
[Game adjustScore];