Is it possible inside Xcode to add a button inside a popover that will take the user to a new view?
Yes.
[myPopOver.contentViewController.view addSubview:myButton];
[myButton addTarget:self action:#selector(goToNextView) forControlEvents:UIControlEventTouchUpInside];
- (void)goToNextView
{
//if you are using xibs use this line
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"myXib" bundle:[NSBundle mainBundle]];
//if you are using storyboards use this line
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"myViewControllersID"];
//to present the controller modally use this
[self presentViewController:controller animated:YES completion:nil];
//or if you are pushing to this controller using a navigation controller use this
[self.navigationController pushViewController:controller animated:YES];
}
Related
I have xib of passcode and after I tap on login button there will be web service that will call and after success response, I have to present xib of passcode.
When I complete that portion I have to push to another view controller from presented xib.
Here is my code:
[self dismissViewControllerAnimated:NO completion:^{
if ([_delegate respondsToSelector:#selector(unlockWasSuccessfulLockScreenViewController:pincode:)]) {
[_delegate unlockWasSuccessfulLockScreenViewController:self pincode:pincode];
PassCodeVC *sgn = [self.storyboard instantiateViewControllerWithIdentifier:#"PassCodeVC"];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:sgn];
[nav pushViewController:sgn animated:YES];
}
}];
and I have presented xib like this:
JKLLockScreenViewController * viewController = [[JKLLockScreenViewController alloc] initWithNibName:NSStringFromClass([JKLLockScreenViewController class]) bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
[viewController setLockScreenMode:LockScreenModeNew]; // enum { LockScreenModeNormal, LockScreenModeNew, LockScreenModeChange }
[viewController setDelegate:self];
[viewController setDataSource:self];
[viewController setTintColor:[UIColor colorWithRed:53.0 / 255.0 green:115.0 / 255.0 blue:157.0 /255.0 alpha:1]];
[self presentViewController:nav animated:YES completion:nil];
If you wish to use current navigation then Just simple pass new controller using current navigation controller.
PassCodeVC *sgn = [self.storyboard instantiateViewControllerWithIdentifier:#"PassCodeVC"];
[self.navigationController pushViewController:childViewController animated:YES];
You may need to set the Storyboard ID of the View Controller you are trying to load. This is located in the inspector, just below where you assign a custom class to your view controller.see this image
I want to be able to show a viewController when a button is pressed.
I don't want to use a navigation controller anymore, is there a way to display it using a modal?
Here is how I am currently showing the viewController:
- (void) editButtonDidClicked: (UIButton *) button {
EditViewController *viewController = [EditViewController getInstanceWithTag:button.tag];
[self.navigationController pushViewController:viewController animated:YES];
}
You can try below code
I assume that you are using storyboard.
UIStoryboard *board = [UIStoryboard storyboardWithName:#"name" bundle:nil];
viewController *controller = [board instantiateViewControllerWithIdentifier:#"Identifier"]; // Identifier is define in storyboard
[self presentViewController:controller animated:YES completion:nil];
Please check out this link if you are still facing the problem.
Hope this helps you.
I have a UIViewController, and inside that view controller I would like to call a CustomUIViewController without the use of Interface Builder. I've been using this and it works but it requires a storyboard ID.
UIStoryboard *storyboard = self.storyboard;
UIViewController *myVC = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:#"PageID"];
[self presentModalViewController:myVC animated:YES];
Is there a way of going from a UIViewController to a customViewController without the use of segues and IB?
Use this:
UIViewController *myVc = [[UIViewController alloc] init];
[self presentViewController:myVc animated:YES completion:nil];
This will obviously present a new blank view controller, if you want your PageID view then you replace UIViewController with the name of the PageID class (i,e the .h/.m file names)
So i'm assuming this:
PageID *myVc = [[PageID alloc] init];
[self presentViewController:myVc animated:YES completion:nil];
If you want it inside a navigation controller do:
PageID *myVc = [[PageID alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myVc];
[self presentViewController: navController animated:YES completion:nil];
OR if you don't want it to be modal (don't need to create a new navigation controller as it will be added to the existing navigation controller stack i.e. [self navigationController]:
[[self navigationController] pushViewController:myVc animated:YES];
I'm trying to make an app using Interface Builder (instead of Storyboard) for the first time, but I'm stuck. Is it possible to change view using a ViewController in the same XIB?
I'd like that when I tap a button, the view changes to the other ViewController present in the same XIB file. Must I call back an action? If yes, which?
If you have 2 view controllers with 2 .xib files, like this
You can present the NextViewControler from your ViewController's button press method,
-(IBAction) yourButtonPressed:(id)sender;{
NextViewController *nextViewController = [[NextViewController alloc] initWithNibName:#"NextViewController" bundle:nil];
[self presentViewController:nextViewController animated:YES completion:nil];
}
EDIT :
You can present the same viewcontroller like this.
-(IBAction) yourButtonPressed:(id)sender;{
ViewController *viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self presentViewController:viewController animated:YES completion:nil];
}
I am new to iOS Application development, please help me how can I go from one view controller to another view controller on button click?
Follow the below step,let the button selector is
[button addTarget:select action:#selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
and implement the selector as
-(void)buttonClick{
UIViewController *controler = [[UIViewController alloc] init];
[self.navigationController pushViewController:controler animated:YES];}
and also make sure viewController has NavigationController embedded within it and replace UIViewController with the Controller you wish to push.
Use this code in your Objective-C function for navigation -
DashboardViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"DashboardView"];
[dvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:dvc animated:YES completion:nil];
Try this:
nextViewController *obj =[[nextViewController alloc]initWithNibName:#"nextViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
You can use any of approach -
pushViewController: animated: - To Push the view on navigation stack
presentModalViewController:nc animated: - To present the view modally.
YourSecondViewcontroller *temp = [[YourSecondViewcontroller alloc]initWithNibName:#"YourSecondViewcontroller" bundle:nil];
[self.navigationController pushViewController:temp animated:YES];
//or
[self presentModalViewController:temp animated:YES];
Visit this reference for tutorial and working demo code
Hope, this will help you..enjoy
//SAViewController will be your destiation view
// import SAViewController.h file in your current view
SAViewController *admin = [[SAViewController alloc]initWithNibName:#"SAViewController" bundle:nil];
[self presentModalViewController:admin animated:YES];
[admin release];
Try this code:
- (IBAction)btnJoin:(id)sender {
SecondViewController *ViewController2 = [self.storyboardinstantiateViewControllerWithIdentifier:#"SecondViewController"];
[self.navigationController pushViewController: ViewController2 animated:YES];
}