Put this where you want to create the button: (e.g. the Root VC's -viewDidLoad
)
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100.0, 100.0, 100.0, 40.0);
[button setTitle:@"Press" forState:UIControlStateNormal];
[viewController.view addSubview:button];
[button addTarget:self action:@selector(didPressButton:) forControlEvents:UIControlEventTouchUpInside];
And implement this method:
- (void)didPressButton:(UIButton *)sender
{
UIViewController *viewController = [[[UIViewController alloc] init] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…