Everybody..
I have create one universal application..
My app worked fine to only two view..
In iphone app worked fine to MainView -> First View -> SecondView -> ThirdView..
But in iPad only works to MainView -> First View .. After it can not call to SeconfView..
I have call also this view but not called..
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
languageObj = [[LanguageSelection alloc] initWithNibName:#"Language_iPhone" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:languageObj animated:NO];
}
else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
languageObj = [[LanguageSelection alloc] initWithNibName:#"LanguageView_iPad" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:languageObj animated:NO];
}
Nib name also perfect.. View outlet also set in nib file.. But LanguageView not called in iPad only..
Please let me know, is there any wrong thing which i had done..
Thanks..
Now this solved..
I need to add only one line in didFinishLaunchingWithOptions method..
UINavigationController *navCont = [[UINavigationController alloc] initWithRootViewController:menuView];
Thanks for who do their effort to solve my question.. Thanks..
Related
For Example, I have 2 Storybards. In the first Storyboard I have a View with a button and when you press the button the second storyboard should appear.
How can I do that?
Take a look at the docs for the storyboard class
You can create a storyboard using
UIStoryBoard *storyboard = [UIStoryboard storyboardWithName:#"secondStoryboard" bundle:nil];
and get view controllers from it like
UIViewController *initialViewController = [storyboard instantiateInitialViewController];
or
UIViewController *otherViewcontroller = [storyboard instantiateViewControllerWithIdentifier:#"otherController"];
Once you've got your view controllers you can just push them onto your navigation controller I guess.
However, I don't know what will happen with using two storyboard objects in the same view hierachy - it's probably fine but you never know :)
Even though your question is a bit confusing, I think I know what you are trying to do.
You want to use two storyboards. UIStoryboard has a method to retrieve an instance of any storyboard with a given name. So first, set a name for your storyboards and view controllers in Xcode and then load them up, and then from within any view controller:
UIStoryboard *anotherStoryboard = [UIStoryBoard storyboardWithName:#"SomeStoryboardName" bundle:nil];
Afterwards, instantiate the desired UIViewController from any storyboard:
UIViewController *anotherViewController = [anotherStoryboard instantiateViewControllerWithIdentifier:#"SomeViewControllerName"];
You could then push it into your navigation stack, for instance:
[self.navigationController pushViewController:anotherViewController animated:YES];
Modifided to be generic here's the way I do this in my app...
UIStoryboard *alternateStoryboard;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
alternateStoryboard = [UIStoryboard storyboardWithName:#"Alternate_iPad" bundle:nil];
} else {
alternateStoryboard = [UIStoryboard storyboardWithName:#"Alternate_iPhone" bundle:nil];
}
AlternateController *altController = [alternateStoryboard instantiateInitialViewController];
[altController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:altController animated:YES];
If your app is only iPhone or iPad that can be reduced to...
UIStoryboard *alternateStoryboard = [UIStoryboard storyboardWithName:#"Alternate" bundle:nil];
AlternateController *altController = [alternateStoryboard instantiateInitialViewController];
[altController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:altController animated:YES];
You'll probably want to change the last 2 lines to suit the presentation style that you want.
I have an iPad app that uses the storyboard board feature and then I have a separate .xib file for another view. I can switch to the separate view and its fine:
-(IBAction)SecondView:(id)sender{
SecondView *Second = [[SecondView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Second animated:NO];
}
But when I am in the Second View and try going back I do everything the same just with the first view controller, but It just goes to a black screen:
-(IBAction)FirstView:(id)sender{
FirstView *First = [[FirstView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:First animated:NO];
}
What do you guys think? Am I doing something wrong? What is the best way to switch views?
initWithNibName:bundle is for loading nib or xib files.
If you are loading from a storyboard, you need to use
FirstView *First= [self.storyboard instantiateViewControllerWithIdentifier:#"IDENTIFIER"];
IDENTIFIER is defined in your storyboard, it's in the Utilities, Attributes Inspector on the right side.
HOWEVER your real problem is that you shouldn't be loading from the storyboard at all. you should just be calling
[self dismissModalViewControllerAnimated:YES];
That call will clean up the presentModalViewController:animated: that you used to put the modal view controller up in the first place.
You presented SecondView using presentModalViewController:animated:, so you need to dismiss it using dismissModalViewControllerAnimated:.
- (IBAction)FirstView:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
I am using XCode 4.0.
I am Transiting from my iPhone App to IPad as a universal app?
I have some doubts for xib files?
Should I use the autoresize element for each UIElement?
Or
Trasit each xib file to the ipad xib file?
How? Could not get the option for that?
.
Use different .xib files for iPad and iPhone and initWithNibName:bundle:. Determine whether to use one or another using this block
NSString *nibName = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
nibName = #"CustomViewControllerIpad";
}
else {
nibName = #"CustomViewControllerIphone";
}
CustomViewController *viewController = [[CustomViewController alloc] initWithNibName:nibName bundle[NSBundle mainBundle]];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
I am an iOS development newbie. I want to go to another page (CountryViewController) from my current page (CityViewController) on the click of a button. How would I do that? Pardon me if this is a very beginner question.
There are several ways. I assume you are using a UINavigationController. If so then you can create the VC and do this inside of your parent view controller.
[self.navigationController pushViewController:viewController animated:YES]
So basically you are trying to build a multi-view app. There are many ways to do so. Bu I'll list 3 common ones -
[self.view insertSubview:newViewController.view atIndex:3];
Using UINavigationController
Finally using modalViewController - [self presentModalViewController:newViewController animated:YES];
In second method, I use this controller without UINavigationTabBar. Hide this navigationBar & provide custom buttons based on which [self.navigationController popViewControllerAnimated] should occur.
ViewController2 *newView = [self.storyboard instantiateViewControllerWithIdentifier:#"viewController"];
[self.navigationController pushViewController:newView animated:YES];
set storyboard id in ViewController2 "Identity inspector".
I have came across the same problem. While User logged in once need to redirect to different page or else need to stay in homepage by default.
Here is the code snippet.
Here
N_loginmsg = #"success";
NSString *N_loginmsg = [[NSUserDefaults standardUserDefaults]objectForKey:#"remember_loginmsg"];
NSString *storyboardId;
if (N_loginmsg != nil && [N_loginmsg isEqual:#"Success"])
{
storyboardId = #"ListViewController";
}
else
{
storyboardId = #"HomeViewController";
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];
UINavigationController *mynav = [[UINavigationController alloc]initWithRootViewController:initViewController];
self.window.rootViewController = mynav;
[self.window makeKeyAndVisible];
hello i am having same issue, i tried your solution but it didnt help me in my case..
i am not getting exception but view is not getting changed..
my piece of code is as below
printf("hi");
//Get the selected country
NSString *selectedCountry = [listOfItems objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
DetailViewController *aSecondView = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
// aSecondView.selectedCountry = selectedCountry;
[self.navigationController pushViewController:aSecondView];
[aSecondView release];
aSecondView = nil;
printf("bye..");
both hi and bye gets printed but view doesnt change..
i have wasted 2 days around it ..
plz help me out..
Check the nib name.How did you created the nib file for the detail view?.It will be created by default as DetailViewController in your case.So change the initWithNibName.Why do you set the aSecondView=nil?
as kovpas said , that subclass your controller from UIViewController instead of UINavigationController ,you use presentModalViewController. for implementing navigation controller put this code in your delegate class
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UINavigationController *nvcontrol =[[UINavigationController alloc] initWithRootViewController:viewController];
[window addSubview:nvcontrol.view];
[window makeKeyAndVisible];
}
Seems, that you subclass your controller from UIViewController instead of UINavigationController
Try to use
[self presentModalViewController:aSecondView animated:YES];
Dismiss it with
[self dismissModalViewControllerAnimated:YES];
in case if you un comment your commented code...one another problem that i found in your code... interchange these 2 lines...
aSecondView.selectedCountry = selectedCountry;
[self.navigationController pushViewController:aSecondView];
try Put it like this
[self.navigationController pushViewController:aSecondView];
aSecondView.selectedCountry = selectedCountry;
if you uncommnet the line it may create problem