0

メインのViewControllerがあります:

@interface ViewController : UIViewController

そこに私のScreenViewを持つプロパティがあります:@property (strong,nonatomic) MUIScreenView* screenView;

そして、それは次のように呼び出されます:

- (void)viewDidLoad
{
    [super viewDidLoad];   
    [self.view addSubview:_screenView];
}

次に、私の MUIScreenViewClass を見てください。

@interface MUIScreenView : MUIView

@interface MUIView : UIView

私の MUIScreenView にはメソッドがあります:

-(void)addScreenObjectToView
{
   MUIButton *button = [[MUIButton alloc] initWithButtonModel:(ButtonModel*)MUIElement 
   [self addSubview:button];

   UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
   myButton.frame = CGRectMake(10, 220, 300, 40);
   [myButton setTitle:@"This is Standard UIButton!" forState:UIControlStateNormal];
   [myButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
   [self addSubview:myButton];

}

そして、これは何かを描画するための私の MUIButton メソッドです:

-(void)addButtonToView
{
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(10, 50, 300, 40);
    [myButton setTitle:@"This is a MUIButton!" forState:UIControlStateNormal];
    [myButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:myButton];
}

そして最後に私は持っています:

ここに画像の説明を入力

トップボタンが死んでいる可能性はありますか?私がそれに触れても何も起こりませんでした。まったく同じ方法で作成しました。

要約 - 「これは MUIButton です!」として現在表示しているもの ビューには別のビューが含まれており、2 番目のビューには UIButton があります。「これは標準の UIButton です!」として UIButton を含むビューです。

4

1 に答える 1

1

メイン ビュー コントローラーのビューへの参照をサブビューに渡し、そのビューにボタンを追加する必要があります。別のビューでセレクターを呼び出して、正しいビューにそれを受け取ることはできません。

于 2012-07-31T17:45:44.047 に答える