iOS Storyboard UIObject won't be displayed - ios

I am quite new in iOS development and I just finished following a series of tutorias to finally start myself. I decided to start from a blank based project to understand all the links and definition that must be made to create a simple view based project.
So I created the storyboard, add a view in it, create a custom class to implement it, link the class to the view on the identity inspector. I also had to change the "application didFinishLaunchWithOptions" to be sure that my view was loaded correctly by simply removing all codes and leaving the "return YES;" like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
Then I added an UIButton in the ViewController.m that I created before and add it to the ViewController's view. When I start the simulator I can see and click the button.
Finally I added a button directly by the storyboard, link it to the ViewController.h but this time it won't display on the simulator. I added several labels, images,... , by the storyboard and none of them can be seen. I added the same content by coding it and it displays correctly this time. What am I missing here?
If I am doing it now it is because I want to be able to add a new UIViewController to any of my project in the future and being able to implement it both with code and the storyboard.
Your help would be much appreciated!
Thanks!
Antoine

Related

Moving project from XIB/NIB to Storyboards

I have a project that I originally started working on in Xcode 4. I then moved this project to Xcode 6. The project compiles and runs swimmingly. I then wanted to move this to use Storyboards.
Reading here and elsewhere I see people say they accomplished this by doing the following:
Create storyboard
Drag a viewcontroller onto the storyboard
Click on the white of the viewcontroller
Delete it Goto the original XIB and copy the entire view
Paste that into the viewcontroller on the new storyboard
Go into the appdelegate.m file and edit the didFinishLaunchingWithOptions section to look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
No errors in my code. Builds fine but instead of seeing the new Storyboard / ViewController, I just see a black screen. Im sure I am missing something somewhere but I cannot seem to find what it is.
If you would like to see my code, I have it here: https://github.com/martylavender/LittleToDoApp/tree/Storyboards
Thanks
You need to set your first view controller as the initial view controller in your storyboard.
You just need to check the is initial View Controller line on the right panel
I figured it out.
Looking at the build information of the project, I hadnt set the Main Interface to the MainStoryboard. That with the earlier suggestion fixed it!!
Thanks!!!

Load custom view instead of default view in iOS app

I have some problem in creating View(must open at start of app) in already existing project.
I have project from https://github.com/emysa341/Login-with-gmail-google-g--using-oath-2.0-protocol , when i run this project it directly goes to login page but i need to change that to home screen. i.e when i click on button in first view then it has to go to login page.
I tried creating .h,.m and .xib file and tried to load these files first as soon as app starts but i am not getting that.
Just tell me process "How to create .xib file in an existing project and make that xib(created by me,not default) to load first?". I googled but no perfect solution.I tried changing code in appdelegate.m but no use.
In this method of appDelegate add this line
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
YourViewController *yourViewController=[[YourViewController alloc]initWithNibName:#"YourViewController" bundle:nil];
self.navController=[[UINavigationController alloc]yourViewController];
self.window.rootViewController=self.navController;
[self.window makeKeyAndVisible];
return YES;
}
If you are using storyboards, you set the first view there. Just open the .storyboard file in Xcode, and there should be an arrow that is faded out on one end, and the head of the arrow should be pointing to a view controller. Just click-and-drag that arrow to the view controller you want to show first, and you should be good to go.
Alternatively (still in the .storyboard file), select a view controller and in the Attributes Inspector there is a checkbox for "Is Initial View Controller" - check that box for the view you want to show up first.

In XCode 4.6 how do you create a brand new iOS application combining a tabbed main application with a navigation controller on one of the tabs?

I am trying to add a navigation controller inside a tab bar controller in a brand new non-storyboard (plain old nib) style.
I found this demo which assumes that XCode has a new project template called "Tab Bar Application". It doesn't. Now XCode 4.6 has "New Tabbed Application". Of course, Apple in their great wisdom has decided that I should not have a main window nib (.xib) and should have the tab bar controller and its pages coded for me in the app delegate instead of in a new-user-friendly NIB instantiated tab controller. I guess that's because it's more flexible that way, and you can write code to decide what tabs the user sees and what tabs they don't see. If I turn on Storyboards, then I guess I can do everything visually still.
I am deeply confused by the long and tortured history of XCode version differences, which affect the validity of existing questions on stackoverflow and demos elsewhere on the web, that reference different iOS versions, and different XCode versions, and make assumptions specific to versions of XCode and iOS that now appear to have changed, and which each rely on different choices with respect to the contents of your Main Nib File Base Name being set or not set.
I also find that it seems that pre-storyboard-Nibs and the complexities of combining various UIKit widgets and controllers has been a primary motivation behind the creation of storyboards.
I am working in a real non-storyboard nib-based application that appears to have been created before this change of heart at apple, and I can see that at startup a lot of unecessary views are created automatically by nib-instantiation and then deleted, in order to dynamically hide and show tabs on the tab bar controller. This appears to have been thought about a great deal at Apple, and they've changed the recommended practices implicitly by changing the way new applications are generated in XCode. I'm not questioning their wisdom, in fact I appreciate the change, but it's left me lost and confused.
Anyways, I'm just trying to put a navigation controller inside a tab in the main tab bar, and I already have an application that must have been started back when XCode used to generate a main window and generate a "Tab Bar Application" with a top level view that is a tabbed view, and the tab bar controller is nib instantiated. The demo above assumes as much.
Apple apparently famously never has provided a demo of this obvious combination of tab bar plus navigation controller. Or so I'm told. And the Apple Human Interface Guidelines apparently state (or used to state?) that it's better to put a navigation controller inside a tab bar than vice versa, and my question should be understood as wishing to comply with the HIG however possible, so I believe I'm asking about the recommended combination, not the discouraged combination.
Here's what I've tried so far:
Tried to follow this blog post, from circa 2009, which assumes things true about older versions of XCode that are no longer true.
Starting with a new tabbed application which XCode generated for me, with storyboards turned OFF, I have a root app delegate .m file that it generated for me that apparently creates at app-startup time, a Tab Bar Controller object completely in code, and which has no Main Window nib. The following code is entirely written by Apple, and I am wondering where (as a relatively new Cocoa developer) I'm supposed to break into this and place my new stuff, if I wanted to change one of the tabs to hav a nav bar and its associated UINavigationViewController:
-- This marker helps stackoverflow's busted markdown system not be confused --
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[RPDAFirstViewController alloc] initWithNibName:#"RPDAFirstViewController_iPhone" bundle:nil];
viewController2 = [[RPDASecondViewController alloc] initWithNibName:#"RPDASecondViewController_iPhone" bundle:nil];
} else {
viewController1 = [[RPDAFirstViewController alloc] initWithNibName:#"RPDAFirstViewController_iPad" bundle:nil];
viewController2 = [[RPDASecondViewController alloc] initWithNibName:#"RPDASecondViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
It now appears that what used to be possible without writing code (according to that 2009 example on the blog I linked to) is now done purely in code. I have read about 500 pages of "Programming iOS 5", worked for a few hundred hours on my first app, and tried a lot of demo applications but I'm still a relatively unseasoned Cocoa/iOS developer, and I believe part of my confusion over all this is the "controller and view" pattern, and its rules for combining them, both in code, and in nibs, are not entirely clear to me.
--
Update: You can has teh codez! In the interest of helping out future XCode-cocoa-iOS noobs like me, I have made a complete demo app and posted it on github here.
Screenshot:
I was as confused as you were when I did the same thing, but once you understand the structure you will find out that it is quite simple.
Basically, You want to create a UINavigationController with the RootViewController you want to display first:
[UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:theViewControllerYouWantToDisplayFirst];
Then just add this controller to the array for your tab buttons.
NSArray *tabs = [[NSArray alloc]
initWithObjects: navController, otherTab, etc];
Then, set your tabs using such array.
UITabBarController *rootController = [[UITabBarController alloc] init];
[rootController setViewControllers:tabs];
and add it to your tab controller to your window:
[self.window setRootViewController:rootController];
And that is it. I took me some time to realize the way things are structured. The Tab View controller just holds a bunch of ViewControllers, you just need to make one of those view controllers your NavigationController.
If you don't mind starting a new app to get the basics going, try this:
Create a Tabbed Application (or whatever it's called nowadays):
Then select the view you want to have embedded in a NavigationController.
Then go to Editor -> Embed -> in NavigationController like shown below:
Your result will look like this:
Cheers!
As explained in the first two answers (both correct), I add another method to come back to the original "Tabbed Application" template (maybe version 3 of XCode? I don't remember).
In this template you'll have a main xib file with, inside, your TabBarController.
You must start from the Empty Application template, then go through this steps:
Add a new file, User Interface, Application Xib. In this tutorial I'll assume you will name it "Application.xib"
Go to your AppDelegate.h file and change this line:
#property (strong, nonatomic) UIWindow *window;
adding IBOutlet:
#property (strong, nonatomic) IBOutlet UIWindow *window;
Go inside AppDelegate.m and change your applicationDidFinishLaunching method with this
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// delete all and leave only the return
return YES;
}
Go inside Application.xib, select "App Delegate" from the Objects Menu, and then in the identity inspector change the Class --> write AppDelegate (or your AppDelegate.h class name)
Always in Application.xib, right click again on App Delegate Object, you will see a "window" Outlet --> link it to the Window object in the Object inspector on the left
Now, come back to the project, go in supporting files, main.m and change the return line like this:
:
return UIApplicationMain(argc, argv, nil, nil);
then, go inside the main .plist file and add a key: right click, add, key, "Main Nib File Base Name", Type String, Value "Application" (without quotes, without .xib extension)
Ok, now you have an empty "old style" nib application. Now you can go again inside Application.xib, drag your TabBar and link it as the Window "root view controller" (right click on the Window, link the root view controller property).
Then, inside the tab bar, you can drag ViewControllers, Navigation controllers, ecc...
If you need other details or images write me
EDIT:
I uploaded a sample project if you want to look: http://www.lombax.it/documents/ManualTab.zip
Screenshot:
I had a working application that I wanted to place under one "leg" of a tabbed application. I wanted to develop other portions of the "bigger app" under the other tabs. I didn't want to use storyboards. That removed a good deal of the solutions I found. Most of the remaining solutions were developed using older versions of Xcode and they simply wouldn't work with the version of Xcode I downloaded in Feb of 2013.
I tried creating my own tabbed application - (starting with an "Empty Application") as some of the developers on this thread had used. I felt like I was getting close, but I simply couldn't get it to work.
There is an excellent tutorial on using a "Tabbed Application with a Navigation Controller" by Vishal Kurup.
With a minor modification (listed below) by following the video I was able to slip my existing application under the default "Tabbed Application" created by Xcode.
Create a TabBar Controller with a Navigation Controller + Detail View in Xcode 4.3
can be found at
http://www.youtube.com/watch?v=UMpNbCs4mr4
the only real change I had to make from the default "Tabbed Application" was in the AppDelegate.m:
the following code supplied by the selecting "Tabbed Application" wouldn't serve my purpose
self.tabBarController.viewControllers = #[viewController1, viewController2];
this did
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigation ,
viewController1 ,viewController2, viewController3, viewController4, nil];
A big thank you goes out to Mr Vishal Kurup.
He has made a number of quality videos on iOS development.

Changing Tabbarcontroller tab in wenderlich tutorial pulse uitableview

I'll be really grateful for any help with this - i've been trying to figure out how to change tabs on a tabbarcontroller from within a nested UITABLEVIEW as in RayWenderlich.com's tutorial on a pulse like scroller http://www.raywenderlich.com/4723/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-2 but am getting really stuck. I am using storyboards and xcode 4.4
I'm completely new to xcode as of a few weeks so I apologise if this is a newbie question. I have got the nested horizontal tableviews working fine as per the image in the link above but I want to use the images to switch to a new tab but can't - I think this is because the tableview is nested so I can't find the right reference to the tabbarcontroller in the hierarchy.
if I use ArticleListViewController.m didselect where the tutorial included comments seem to suggest to insertion navigation code will generate an NSLog output and change tabs ok but only using a tiny thin strip above the images (I discovered this by accident) but nothing happens with the images.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller
//THIS SELECTS WHEN CLICK THINSTRIP JUST ABOVE BUTTONS
NSLog(#"ARTICLELISTVIEWCONTROLLER check didSelect: %u", self.tabBarController.selectedIndex);
self.tabBarController.selectedIndex = 2;
}
the following code within HorizontaTableCell.m more appropriately generates an NSLog output when I click on the actual images but I can't figure out the tabbarcontroller reference that allows me to change tabs.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//the following line just generates an Error as follows: Property tabBarController not found on object of type 'HorizontalTableCell *'
self.tabBarController.selectedIndex = 2;
NSLog(#"HORIZONTALTABLECELL DIDSELECT");
}
Ive looked and looked for a way round this but can't figure it out. Found a mention of using appdelegate but not sure how to do this. can't post storyboard image as new user but has a tabbarcontroller with 4 navigation controllers coming out - the first is the ArticleListViewController menu and each of the others are viewcontrollers - one I hope to put a webview that loads a link/local page depending on the menu selected and the others for an about screen and an additional currently blank screen.
Please help!
thanks!
I'm guessing you have the tabBarController as a property in your app delegate?
You can reach your app delegate with:
[[UIApplication sharedApplication] delegate]
Cast that to your app delegate class and the compiler will not warn you for reaching at the tab bar controller. Like this:
((YourAppDelegate *) [[UIApplication sharedApplication] delegate]).tabBarController.selectedIndex = 2;
As for the tableview delegate method, ArticleListViewController sounds like the place where you'd want that. The cells should just be dumb views with minor presentation logic at most. If it is not getting called, make sure you've set it up as a delegate for the table view properly (in interface builder if you followed that tutorial you linked to).

iOS Splash Page while Loading Data

I am trying to write an app that displays a simple logo/splash page while the app retrieves some data. I cannot seem to find a tutorial anywhere.
I have a "MainWindow.xib" file that will have my splash page, and I'm setting that as my "Main Interface" in my Info.plist, however, I cannot seem to see how to replace that page with a .xib that contains a UINavigationController. I thought I would just create a new UIController, that had a UINavigationController and in my .xib I'll drag in a Navigation Controller and set all my information, but it's giving me real fits.
So, I figured I would have a UIController that I would "alloc" and "init" with my second .xib that contains all my navigation.
myMainController = [[UIController alloc] initWithNibName:#"MainNavController":nil];
in "MainNavController.xib", I've dragged in a Navigation Controller, but I don't know what to connect it to????
I'm sure I'm going down the wrong, path; but I cannot find a decent tutorial for this.
Can someone give direction or link to a decent tutorial?
Thanks.
Are you ever actually adding the new controller to your existing view? If not, something like:
[self.view addSubview:myMainController.view];
should do it for you. A better alternative is likely to be:
self.window.rootViewController = myMainController;
But I'm fairly new to this and maybe I've missed something ...
To display a splash screen while the app is loading you can use Default.png image file.
However, I think your question is how to display another splash screen for a period of time after the app has been loaded.
In you MainWindow.xib keep your window separated from your Navigation Controller. Add your splash screen view with an image to the xib.
Make two outlets: one for slash view, one for Navigation Controller.
IBOutlet UIView* _spashScreenView;
IBOutlet UINavigationController* _navigationController;
In applicationDidFinishLaunching method add your splash screen view to the window.
[_window addSubview:_spashScreenView];
// lay it out
When you are ready to display your navigation controller:
[_spashScreenView removeFromSuperView];
[_window addSubview:_navigationController];

Resources