I am new at the area of Objective-C and am building an iphone app using Xcode. I have taken two buttons on a page and from among one I would like to go to another page. How is it possible at Xcode?
You can try it.
EnterNameController *newEnterNameController = [[EnterNameController alloc] initWithNibName:#"EnterNibFileName" bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:newEnterNameController animated:YES];
EnterNameController *newEnterNameController = [[EnterNameController alloc] initWithNibName:#"EnterNibFileName" bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:newEnterNameController animated:YES];
[newEnterNamecontroller release];
This one is more accurate as far as i know.
This type of thing is a basic building block of iPhone apps, and Apple provides plenty of sample code that shows how to do it.
Start by looking at the UICatalog sample project.
Get the book "Beginning iPhone Development" and go through it from start to finish without skipping anything.
You can try
TwoViewController * twoVC = [[TwoViewController alloc] init];
[self.navigationController pushViewController:twoVC animated:YES];
"TwoViewController" is a custom UIViewController
Related
I am totally new with iOS development.I am just trying to open a new page when user will click on button. But it is not working.I am using this code:
(IBAction)btnOpenNewPage:(UIButton *)sender {
FacebookViewController *ls=[[FacebookViewController alloc] initWithNibName:#"loginSuccessViewController" bundle:nil];
[self.navigationController pushViewController:ls animated:YES];
}
But i don't understand why it is not working! I am using Xcode 6. I think i need to add some parameter or code in other files. Please help me.
if your code there doesn't work then you probably don't have a navigationController. try creating one:
-(IBAction)btnOpenNewPage:(UIButton *)sender {
FacebookViewController *ls=[[FacebookViewController alloc] initWithNibName:#"loginSuccessViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:Is];
[nav pushViewController:ls animated:YES];
}
When I called:
[self.navigationController pushViewController:SOME_VIEW_CONTROLLER animated:YES];
the app randomly stuck (it didn't crash, so no error log). Have tried debugging it with no result.
Note that:
I called this pushViewController from a UIViewController category.
Is there any problem with that?
I am not using storyboard
The problem persist randomly (it doesn't happen all the time)
When it stuck, viewDidAppear won't be called (viewWillAppear, viewWillLayoutSubviews, viewDidLayoutSubviews still
called)
the problem never occured when I use animated:NO
Some code snippets:
- (void)routeToBookingDetailsForCustomer:(BookingModel *)booking {
VTBookingDetailsForCustomerViewController *vc = [VTBookingDetailsForCustomerViewController new];
vc.booking = booking;
[self.navigationController pushViewController:vc animated:YES];
}
Just found another thread with similar case:
pushViewController stuck or viewdidappear fail
I think you have to pass Nib name as well like this
- (void)routeToBookingDetailsForCustomer:(BookingModel *)booking{
VTBookingDetailsForCustomerViewController *vc = [[VTBookingDetailsForCustomerViewController alloc]initWithNibName:#"VTBookingDetailsForCustomerViewController" bundle:nil];
vc.booking = booking;
[self.navigationController pushViewController:vc animated:YES];
}
Nib name means your XIB name whatever XIB name for your VTBookingDetailsForCustomerViewController, you have to pass this in initWithNibName:#"yourXIBname"
Have you tried this approach?
someViewController *someVC = [someViewController alloc] initWithNibName:#"someViewController " bundle:NULL];
someVC.someVariable = someValue;
[self.navigationController pushViewController:someVC animated:YES];
Edit : Just saw 'Dipen Chudasama' already answered!
Are you using custom transition animations by implementing UINavigationProtocolDelegate combined with UIViewControllerInteractiveTransitioning?
I struggled with this issue in my own application and it turned out that I was incorrectly starting an interactive transition which I never finished. In this case all debugging showed me that the controller was pushed but UI was not updated until my app changed states.
Please try pushViewController code in main queue.
dispatch_async (dispatch_get_main_queue(), ^{
VTBookingDetailsForCustomerViewController *vc = [VTBookingDetailsForCustomerViewController new];
vc.booking = booking;
[self.navigationController pushViewController:vc animated:YES];
});
I have a navigation controller that pushes a new viewcontroller. It is working fine in iOS6, but not working fine in iOS5. Btw, I am running on iPhone Simulator.
My code looks like this:
myViewController *newView = [[myViewController alloc] initWithNibName:#"myViewController"
bundle:nil];
[[self navigationController] pushViewController:newView animated:YES];
Tried this as well:
myViewController *newView = [[myViewController alloc] initWithNibName:#"myViewController"
bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:newView animated:YES];
Not working.
Tried the solution in this: pushViewController Not Working on iOS 5 (OK on iOS 6).
Not showing the new view controller either, need some guidance on this. Thanks.
Can you try this line just to test if there is some problem with your nib file or not.
myViewController *newView = [[myViewController alloc] init];
[[self navigationController] pushViewController:newView animated:YES];
In - (void)viewDidLoad write self.view.backgroundColor = [UIColor redColor];
just to test whether or not your viewcontroller is pushing.
If you are able to push your View Controller using this method. Then there might be some issue with your nib file.
Do you using storyboard or xib? If you are using storyboard this can help you initwithnibname method in storyboard
I has similar issue. Got it solved by removing 'AutoLayout' constraint inside View to be Pushed.!
I red nearly all the help which is provided, and i'm still confused. I have simple project in Xcode4.2 with sotoryboard. There i have Navigationcontroller and two Viewcontroler (one, two). If i'm trying to get from one to two with pushViewController its break down. Where is my problem. If i have the Navigationcontroler in my storyboard i shouldn't have problem to access it and use it, is it right? I don't won modal window application i use something like story board where the user can move back and front without lose the controls data. How should i do it right.
thanks for any help I'm new to apple developing :)
The only code :
- (IBAction)Next:(id)sender{
two* myNext = [[two alloc] initWithNibName:#"two" bundle:nil];
NSLog(#"%#", [self navigationController]);
NSLog(#"%d", [[[self navigationController] viewControllers] count]);
[[self navigationController] pushViewController:myNext animated:YES];
// [[self navigationController] pushViewController:myNext animated:YES];
// [myNext release];
}
The solution is to change the initialize UIViewController because of using storyboard you can't use initWithNibName. You have to use instantiateViewControllerWithIdentifier which use identifier property of UIViewController. The identifier property can by set in the sotryboard.
ViewController* myNext = [self.storyboard instantiateViewControllerWithIdentifier:#"Next"];
At the end of this code:
UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
The navigation controller appear modally, as usual, but when I click a button on the viewController, it crashes. In fact, the viewController has a retain count of 0.
If I comment one of the two releases everything went better than expected.
I have been seeing this code pretty much everywhere, what could be wrong?
The code you've posted is correct, but somewhere else you're over releasing something.
A few things to note:
First, never trust retainCount.
Second, make sure you're properly managing the memory of your nib objects as outlined here.
Finally, you'll need to use the NSZombie detection in Instruments to find out where your real problem lies. This video provides a nice how to.