2011-11-02 70 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]; 
}