#iphone #iphone-sdk-3.0 #ios4
#iPhone #iphone-sdk-3.0 #ios4
Вопрос:
Я создал кнопку программно, и я хочу запустить событие, чтобы перейти на следующую страницу, событие не генерируется. Что я могу сделать?
Это код:
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];
}
Ответ №1:
Вы выполнили всю работу 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];
}
Это определенно сработает для вас
Комментарии:
1. Посмотрите на мой код__ RegistrationPage * r = [[RegistrationPage alloc] initWithNibName: @»RegistrationPage» bundle: nil]; [self.NavigationController pushViewController: r animated: YES]; // ошибка [r release]; Это выдает мне ошибку, когда я пытаюсь освободить resorce из r! Можете ли вы дать решение?
2. я не понимаю вашу проблему должным образом??
Ответ №2:
Попробуйте так,
[btnSignUp addTarget:self action:@selector(registrationPage:) forControlEvents:UIControlEventTouchUpInside];
Ответ №3:
//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];
}