我已经以编程方式创建了一个按钮,我想触发事件进入下一页,但事件未生成。我该怎么办?
这是代码:
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 :(得分:0)
试试这个,
[btnSignUp addTarget:self action:@selector(registrationPage:) forControlEvents:UIControlEventTouchUpInside];
答案 1 :(得分: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];
}
这绝对适合你
答案 2 :(得分: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];
}