2011-10-03 56 views
3

对不明确的标题感到抱歉。我希望能够IBAction为方法添加到一个按钮,我在下面的方式加:在没有IBOutlet的情况下对UIButton使用IBActions

(.H类)

{ 
    UIButton *button; 
} 
-(IBAction)ButtonReleased:(id)sender 

(.M类)

{ 
    -(IBAction)ButtonReleased:(id)sender 
    { 
     //Actions done by button pointer 
    } 

    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     [PlayButton setFrame:CGRectMake(10, 10, 100, 50)]; 
     [PlayButton setTitle:@"PlayButton" forState:UIControlStateNormal]; 
     [self.view addSubview:PlayButton]; 
    } 
} 

的问题是,如何将UIButton按钮操作(比如TouchUpInside)连接到ButtonReleased方法。

回答

5
[button addTarget:self action:@selector(ButtonReleased:) forControlEvents:UIControlEventTouchUpInside]; 
相关问题