-2

UIView のサブクラスを持つ 1 つのカスタム クラスがあり、この中に 1 つのボタンを動的に作成しました。ここで、ボタン メソッドのアクションを設定します。UIviewController のようにノーマルを設定します。しかし、うまくいきません。

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    UIButton *but=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    but.frame= CGRectMake(200, 15, 15, 15);
    [but setTitle:@"Ok" forState:UIControlStateNormal];
    [but addTarget:self action:@selector(aMethod)
  forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:but];
    // Initialization code
}
return self;
 }

-(void)aMethod
{

    NextEyeViewController *nexteye=[[NextEyeViewController alloc]initWithNibName:@"NextEyeViewController" bundle:nil];
    [self presentViewController:nexteye animated:YES completion:nil];
}

-(void)aMethodボタンの私のメソッド名です

4

3 に答える 3

0

UIButton を作成します。

UIButton *yourButton = [[UIButton alloc] initWithFrame:frameButton];

// Here code to set button properties: color, label...

[yourButton addTarget:self action:@selector(aMethod) forControlEvents:UIControlEventTouchDown];

[self.view addSubview:yourButton];
于 2013-10-05T13:01:40.573 に答える