2011-11-02 50 views
0

我已經創建了一個按鈕編程,我想引發事件去下一頁,事件不會生成。我能做什麼?如何在按鈕上生成事件以通過按鈕iphone

這是代碼:

btnSignUp =[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
btnSignUp.frame =CGRectMake(20,250,280,35); 
[btnSignUp setTitle:@"Sign Up" forState:UIControlStateNormal]; 
[btnSignUp addTarget:self action:@selector(registrationPage:) 
    forControlEvents:UIControlEventAllTouchEvents]; 

    -(void)registrationPage:(id)sender 
    {   
    registration =[[RegistrationPage alloc] initWithNibName:@"Registration" bundle:[NSBundle mainBundle]]; 

     [self.navigationController pushViewController:registration animated:YES]; 

    } 

回答

0

你已經做了所有工作GRT!只需一行更改。

btnSignUp = [UIButton buttonWithType:UIButtonTypeRoundedRect];

btnSignUp.frame =CGRectMake(20,250,280,35); 

    [btnSignUp setTitle:@"Sign Up" forState:UIControlStateNormal]; 

    [btnSignUp addTarget:self action:@selector(registrationPage:) 

forControlEvents:UIControlEventTouchUpInside]; 





-(void)registrationPage:(id)sender 
{ 

registration =[[RegistrationPage alloc] initWithNibName:@"Registration" bundle:[NSBundle mainBundle]]; 

    [self.navigationController pushViewController:registration animated:YES]; 

} 

這會爲你

+0

看看我code__肯定工作 RegistrationPage * R = [[RegistrationPage頁頭] initWithNibName:@ 「RegistrationPage」 捆綁:無]。 [self.navigationController pushViewController:r animated:YES]; //錯誤[r release]; 當我嘗試釋放r的resorce時,它給了我錯誤!你可以給soltuion嗎? – Chintan

+0

我沒有正確地解決你的問題? –

0

嘗試這樣,

[btnSignUp addTarget:self action:@selector(registrationPage:) forControlEvents:UIControlEventTouchUpInside]; 
0
//methodname 
{ 
btnSignUp.frame =CGRectMake(20,250,280,35); 
btnSignUp =[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[btnSignUp setTitle:@"Sign Up" forState:UIControlStateNormal]; 
[btnSignUp addTarget:self action:@selector(registrationPage) 
forControlEvents:UIControlEventAllTouchEvents]; 
} 
-(void)registrationPage 
{   
registration =[[RegistrationPage alloc] initWithNibName:@"Registration" bundle:nil]; 
[self.navigationController pushViewController:registration animated:YES]; 
[registration release]; 
} 
相關問題