I found some sample code.
It show the view by following code in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
NSLog(#"AppDelegate didFinishLaunchingWithOptions");
application.applicationIconBadgeNumber = 0;
}
AITPreviewViewController *previewViewController = [[AITPreviewViewController alloc] initWithNibName:#"AITPreviewViewController" bundle:nil];
navigationController = [[UINavigationController alloc]initWithRootViewController:previewViewController];
[self.window setRootViewController:navigationController] ;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
The following picture is in the AITPreviewViewController.xib.
But the View is not normal when it run on the iPhone , it show like the following picture.
The three imageView on the top has been obstructing by navigationItem
But when I turn to other View , and use the following code to turn back.
UIViewController *Previewer = [[AITPreviewViewController alloc] initWithNibName:#"AITPreviewViewController" bundle:nil] ;
Previewer.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController pushViewController:Previewer animated:YES];
It show the normal View like the following picture.
The View only show not normal at first time...
What happened to this condition ?
Can it use Auto-layout to solve this problem ?
If you don't want to hide navigation bar then in your xib just make a little change
Just change the Top Bar property from none to as shown in image. It will auto place your image below the navigation bar
Try increasing the 'Y' value for those 3 images from your interface builder. Select each image and then go to Size Inspector. There you will see some values. Find the Y value and increase it. This will push the images down.
If you want to show only UI according to "AITPreviewViewController.xib"
Then you can hide your navigation bar.
Related
I'm just doing some ios programming after not touching it for a few months, and I'm new to it this year. I just started a new project, and all I did was programmatically set up a navigation controller as the root view controller.
Here's the code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UINavigationController *nvc = [[UINavigationController alloc] init];
nvc.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
nvc.view.backgroundColor = [UIColor yellowColor];
nvc.title = #"Woah";
// nvc.navigationBarHidden = TRUE; this works ok
self.window.rootViewController = nvc;
return YES;
}
I don't have the reputation points to post an image, but here it is: http://i.stack.imgur.com/tbcqi.png
As you can see the title does not show in the navigation bar. Also, quite oddly, the navigation bar is only across the top left corner and not across the entire view. What am I missing here? Also if I set the commented out line to run, to hide the bar, that does work. But of course I want the bar, I don't not want it.
This is a brand new project I just started fresh, and I tried it in two new projects. I have the same outcome in both cases of this weird left corner bar. Any ideas what I am doing wrong? Thanks.
You need to add a UIViewController as the root of you UINavigationController. At the moment you have no view controllers being managed.
The navigation bar title reflects the contents of each UIViewControllers UINavigationItem. By default the title on the navigation bar is the title of the UIViewController which is top most in the navigation stack.
The back button oddly reflects the title of the UINavigationItem of the UIViewController second from top. So to set the back button label you actually set it in the navigationItem of the controller which pushed the top controller on.
You can change the title by accessing the top view controllers navigationItem or from inside the top view controller using:
<a view controller>.navigationItem.title = #"My New Title";
or if from within the controller:
self.navigationItem.title = #"My New Title";
I am not sure what is your intention to create UIWindow because it's the code for ages ago.
Now when you are upgrade your xCode to the latest version, there's no need to UIWindow to be created manually.
Also, when you are creating UINavigationController, it is much better when you are setting UINavigationController's rootView controller.
I am quite sure there will be UIViewController which need to be nested in UINavigationController.
So your code will need to be changed like below;
HomeViewController *homeVC = [[HomeViewController alloc] initWithNibName:#"HomeViewController"]; //Let's assume this is the first VC on the navigation stack
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:homeVC];
// nvc.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// nvc.view.backgroundColor = [UIColor yellowColor]; use nvc.navigationBar.tintColor = [UIColor yellowColor];
// nvc.title = #"Woah"; use homeVC.title = #"Woah";
// nvc.navigationBarHidden = TRUE; this works ok
self.window.rootViewController = nvc;
I'm totally new to iOS programming. I only programmed on Android so far and Objective-C is a total different and new language for me now.
What I want to do is to not use a design that I've created with the storyboard. I want to do all programmatically, since I think it will be more dynamic if I do it like this.
The problem I'm encountering is, that I want to have 3 different views. I googled a bit, and stumbled upon some stackoverflow questions. There, people suggested using a NavigationController. Okay. Now I'm trying to implement it. What I want to have is the following
A MainViewController that has 3 different views. The first view is a loginView. The second one is displaying data and the third is displaying detailed data dependent on the click of the second view.
Is a navigationcontroller corerct for this? The problem I'm having is where I tell the app that I want to start with the MainViewController and push the LoginView in it.
I have a MainViewController.h and MainViewController.m that are subclasses of UIViewController
Now, where exactly do I do this? I have the didFinishLaunchingWithOptions method right here with the following content
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
UIViewController *viewController = [[MainViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[navigationController pushViewController:viewController animated:NO];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
But that just crashes the app. What am I doing wrong? How do I get those three views? Am I starting completely wrong? Please help. As I said I'm new to iOS development. It's easy for me to programm on one view. I did that already, but I want thre different views! Thanks!
A MainViewController that has 3 different views. The first view is a loginView. The second one is displaying data and the third is displaying detailed data dependent on the click of the second view.
That's wrong.
You need three different view controllers, each of those will manage its own view.
Then you push one after another in the navigation controller, depending on user interaction.
Yes, Gonzalo Aune is rite, You should not push the rootviewcontroller in NavicationController.
Also , I will Suggest you to keep your first view (Login View) out of Navigation controller.
You can start with your MainViewController and based on check and conditions you can present LoginView on MainViewController using
[self presentViewController:loginViewController animated:YES completion:NULL];
And after successful login you can dismiss LoginViewController.
Remove this:
[navigationController pushViewController:viewController animated:NO];
You shouldnt push the ViewController since you told the NavigationController already that the ViewController would be the root one:
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:viewController];
use this code and if application is universion then use same code else remove the condition of ([[UIDevice currentDevice] userInterfaceIdiom]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *navController;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
{
if(result.length>0)
{
for(var i in result)
{
var ObjResult=result[i];
var content = "<div data-role='collapsible' id='set" + i + "'>";
content+="<h3>"+ObjResult.title+"<br>";
var intDate=parseInt(ObjResult['ordered date']);
content +=timestampToDate(intDate)+"</h3>"
if(isNaN(ObjResult.med_placeorderfor))
content+="<p><a>Medicle Place order for: </a>"+result[i].med_placeorderfor+"</p>";
if(isNaN(ObjResult.pres_placeorderfor)>0)
content+="<p><a>Medicle Place order for: </a>"+result[i].placeorderfor+"</p>";
if(ObjResult['order status'].length>0)
content+="<p><a>Order status: </a>"+ObjResult['order status']+"</p>";
if(ObjResult.comments.length>0)
content+="<p><a>Comments: </a>"+ObjResult.comments+"</p>";
content+="</div>";
}
$("#id_notification_list_dashboard").append( content ).collapsibleset('refresh');
$("#id_notification_list_dashboard").trigger('create');
}
else
{
$("#id_notification_list_dashboard").append("<div style=\"text-align:center\" data-role='list-divider'><h1>No data found</h1></div>").collapsibleset('refresh');
}
$('body').removeClass('ui-loading');
loadingWithMsg("hide");
}
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
navController=[[UINavigationController alloc]initWithRootViewController:self.viewController];
[navController.navigationBar setTranslucent:YES];
navController.navigationBar.tintColor = [UIColor colorWithRed:161.0f/255.0f green:18.0f/255.0f blue:6.0f/255.0f alpha:1];
self.window.rootViewController =navController ;
[self.window makeKeyAndVisible];
return YES;
}
I am a newbie with regards to IOS Development, so I really need help regarding this matter. I have been working in a program where in a have a slide bar as well as a tab bar. However, when I click an item from the slide bar, it goes to the new view and the tab bar disappears. I tried embedding the new view into a navigation controller and adding a push segue between my tab bar controller a to the new view.. but still, tab bar won't show up.
What will I do to retain or use my existing tab bar in my new view? so, it will be visible to the new view.
Thanks! your help is very much appreciated. :)
First, you gotta perform a push, not a modal. Then, you could use this method hidesbotTombarWhenPushed in the view controller that pushes, that should do the trick.
If not, maybe you can clarify more or post some code :)
This may be because of you are not adding tabview controller as the window's root view controller in AppDelegate. Check the sample code below
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
searchController = [[SearchController alloc]initWithNibName:#"SearchController" bundle:nil];
navCtrl1 = [[UINavigationController alloc]initWithRootViewController:viewController];
navCtrl2 = [[UINavigationController alloc]initWithRootViewController:searchController];
NSMutableArray *viewControllersArray = [[NSMutableArray alloc]init];
[viewControllersArray addObject:navCtrl1];
[viewControllersArray addObject:navCtrl2];
tabController = [[UITabBarController alloc]init];
tabController.viewControllers = [NSArray arrayWithObjects: navCtrl1 ,navCtrl2,nil];
self.window.rootViewController = tabController;
[self.window makeKeyAndVisible];
return YES;
}
I just recently started programming for iOS/iPhone. I thought I knew what I was doing until XCode5/iOS7 came around. Previously, I created a class derived from UIViewController with a XIB, added a label, and programatically added it to the rootWindow:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
... // boilerplate code
MyViewController* myRoot = [[MyViewController alloc]init];
self.window.rootViewController = myRoot;
To use a navigation bar, I changed the code slightly:
MyViewController* myRoot = [[MyViewController alloc]init];
UINavigationController* navigationController = [[UINavigationController alloc]init];
[navigationController pushViewController:myRoot animated:YES];
self.window.rootViewController = navigationController;
This seemed to work fine. However, on iOS 7 the controls at the top of my custom view controller appear to be behind the navigation bar. Some googling resulted in this link which describes changes in the status bar.
It also seems to indicate that,
A) UINavigationController should handle the changes automatically
B) "auto layout" should handle the changes automatically,
and that I shouldn't need to worry. However, my sample app above doesn't appear to handle anything automatically.
I also found some other sample code which uses the controller differently: adding the navigation controller's view as a subView to an existing view. This sort of makes sense for adding a navigation controller later on in an app's lifetime, but I am trying to set one up on launch.
Am I using the UINavigationController correctly?
What do I need to consider for iOS7 vs. earlier versions?
How do I configure "Auto Layout" (I don't see this in interface builder anywhere)?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
I have a problem I can't figure out, I have made an application which uses UIsplitview inside a tab bar. I have been implementing the different tabs however now when I am working on the first tab - the UIsplitview is not aligned in landscape mode. Do you guys have any suggestions - if I start it in portrait and go to landscape, then there's no problem at all.
Update:
I dont do any init with frames anywhere, and I have checked the sizes etc. in IB. The following shows how I add the uisplitview controller in the app delegate. It has been done this way because I wanted a splitview in a tabbar controller. When i have added the spilview I just set the master and detail view in IB. A bit of mystery.
if (index == 2) {
detailViewController = [[DetailUserCreatorViewController alloc] initWithNibName:#"DetailUserCreatorView" bundle:nil];
userContent=[[UserContentForPopViewController alloc]init];
userContent.userDetails=detailViewController;
detailViewController.delegate=userContent;
//rootViewController.navigationItem.title = #"List";
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:userContent] autorelease];
splitViewController = [[UISplitViewController alloc] init];
splitViewController.tabBarItem = controller.tabBarItem;
splitViewController.viewControllers = [NSArray arrayWithObjects:nav, detailViewController, nil];
splitViewController.delegate = detailViewController;
[controllers replaceObjectAtIndex:index withObject:splitViewController];
}
Update: I tried to set the selected tab in application didfinishlaunch in the app delegate - self.tabBarController.selectedIndex = 0; and this made the tab start at the correct placement. However it does not seem to be a proper solution.
Some pointers...splitViewController needs to be added as a subview of window:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
return YES;
}
The following code is incorrect. You should not assign a viewController to a delegate.
splitViewController.delegate = detailViewController;
You will also not require this line of code:
[controllers replaceObjectAtIndex:index withObject:splitViewController];
The following line handles that part of assigning delegates.
splitViewController.viewControllers = [NSArray arrayWithObjects:nav, detailViewController, nil];
Also, if you can upload your code, I'll try to correct it and post back the reason and corrected code...