我有一个按钮子视图的主视图 StartScene.h:
@class PlayScene
@interface StartScene : UIView <UITextFieldDelegate> {
PlayScene* tView;
UIButton *Ok;
}
StartScene.m中的某个地方:
Ok = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[Ok setFrame:CGRectMake(100, 190, 65, 30)];
[Ok setTitle:(NSString *)@"OK" forState:(UIControlState)UIControlStateNormal];
[Ok addTarget:self action:@selector(gameOverDidLoad) forControlEvents:UIControlEventTouchDown];
[self addSubview:Ok];
Ok.hidden=YES;
Ok.enabled=NO;
tView = [[PlayScene alloc]initWithFrame:CGRectMake(0, 0, 320, 520)];
tView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backGround.jpg"]];
[self addSubview:tView];
和子视图: PlayScene.h:
#import "StartScene.h"
@interface PlayScene : StartScene {
}
PlayScene.m:
- (void)ooneFingerTwoTaps {
[NSThread detachNewThreadSelector:@selector(oneFingerTwoTaps) toTarget:self withObject:nil];
}
被调用,方法是
- (void)oneFingerTwoTaps
{
// some code
if (self.GameState==GameLost) {
[super checkScore:xScore];
Ok.hidden=NO;
Ok.enabled=YES;
[[NSThread currentThread] cancel];
}
}
}
所以当PlayScene中发生某些事情时需要Ok按钮。
我试过
Ok.hidden=NO;
Ok.enabled=YES;
但它不起作用。我想,由于子视图只能看到一个尚未初始化的UIButton变量。
所以我在这里有2个问题:
1)我可以使用self.Ok或super.Ok调用Ok变量。我认为super.Ok完全可以工作,但我不知道,我在这里找不到合适的语法。它是什么?
2)可能是其他方式可以解决的问题吗?