2011-10-03 61 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]; 
相關問題