UIViews not showing in my window based template? - iphone

UIView not shown on my window based template?
I am creating an app for this a was use the window based template and a view controller and for checking drop label but after execution it appears like clean white window.
in delegate header file i do this
#import "First_View.h"
#class First_View;
#property (nonatomic, retain) First_View *viewcontroller;
And in delegate.m
#synthesize viewcontroller=_viewcontroller;
//in implementation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewcontroller; /*/**main line code here**/*/
[self.window makeKeyAndVisible];
return YES;
}

You can add the ViewController View to the window like that:
[self.window addSubView:self.viewcontroller.view];
And the view Controller should have an outlet if you are creating it using Interface Builder and don't forget to connect it:
#property (nonatomic, retain) IBOutlet First_View *viewcontroller;

Related

pressing a UITabBar button Programmatically in Xcode

i used the code below to make a UITabBarController :
inside AppDelegate.h:
IBOutlet UITabBarController *rootController;
...
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
inside AppDelegate.m
#synthesize rootController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
Now i need to know how to implement this method inside AppDelegate:
- (void)SwitchToTab:(int)index{
//go to tabview 1 or 2 ...
}
You can do this:
self.rootController.selectedIndex = 2; // or whatever index you like
or this:
self.rootController.selectedViewController = oneOfTheViewControllersInTheTabController;
See the UITabBarController reference page for details.

How to properly add a Navigation Controller to my Search View with hidden Navigation Bar

When my app is launched the first screen (view) the user sees when my app is launched is a search form without any navigation. Navigation will show up after search process is done and results are ready to be displayed. Where I'm stuck at is the proper way to make it work with the navigation controller.
So, assuming the app name is RealEsateProperties
In RealEsatePropertiesAppDelegate.h:
#import <UIKit/UIKit.h>
#class RealEsatePropertiesViewController;
#interface RealEsatePropertiesAppDelegate : NSObject <UIApplicationDelegate>
{
UINavigationController *ListingNav;
}
#property (nonatomic, retain) IBOutlet UIWindow window;
#property (nonatomic, retain) RealEsatePropertiesViewController *viewController;
// Then I added this line for the navigation
#property (nonatomic, retain) UINavigationController *ListingNav;
#end
and in RealEsatePropertiesAppDelegate.m:
#import "RealEsatePropertiesAppDelegate.h"
#import "RealEsatePropertiesViewController.h"
#synthesize window=_window;
#synthesize window=_viewController;
#synthesize ListingNav;
#implementation RealEsatePropertiesAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLanchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.viewController;
// Iadded the following 4 lines to try making the navigation thing work without showing any navigation bar on the first screen (that is the search form)
self.ListingNav = [[UINavigationController alloc] initWithRootController:self.viewController];
self.ListingNav.navigationBarHidden = YES;
[self.window addSubView:ListingNav.view];
[self.window makeKeyAndVisible];
return YES;
}
#end
Am I doing anything wrong ?
Thx for helping,
Stephane
You need to create/alloc your RealEsatePropertiesViewController ?
viewController = [[RealEsatePropertiesViewController alloc] init];

Error with simple UILabel?

I have a little problem:
I have a view with a view controller and a tabbarcontroller in a main window.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the tab bar controller's current view as a subview of the window
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
On this view I have around 10 Labels.
As soon as I connect 1 Label on the Interface-Builder with the UILabel in the controller, I get a SIGBART error.
Here is my code:
#import <UIKit/UIKit.h>
#interface SelfViewController : UIViewController
{
IBOutlet UILabel *id2;
IBOutlet UILabel *username;
IBOutlet UILabel *vorname;
IBOutlet UILabel *nachname;
IBOutlet UILabel *email;
}
#end
What am I doing wrong?
Here is a solution, very basic and simple but very frustrating too:
https://discussions.apple.com/thread/1598422?threadID=1598422

Adding UIViewController subclass with IBOutlet

I have seen this example on Apple's website before, but for some reason, I cannot find it and am brainfarting. I created a TestViewController.h and .m file that subclass from UIViewController and have a .xib. In the TestAppDelegate.h, I have:
#interface TestAppDelegate : NSObject <UIApplicationDelegate> {
TestViewController *rootController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet TestViewController *rootController;
in TestAppDelegate.m, I have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
Then in my MainWindow.xib, I drag a ViewController, change the class to TestViewController, control drag the outlet from TestAppDelegate to TestViewController. It builds fine, but when I run it I get:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TestViewController 0x4d06570> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label.'
I cannot remember what I'm missing in these steps. Any help would be appreciated. Thanks.
#interface TestAppDelegate : NSObject <UIApplicationDelegate> {
TestViewController *rootController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet TestViewController *rootController;
in TestAppDelegate.m, I have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}
IF IT IS THE CODE YOU ARE REALLY USING THEN ADD FOLLOWING LINE TO YOUR INTERFACE:
UIWindow *window;
AND CHECK IF IT HELPS.
For your window you need to setup you rootViewController. By the way your naming "rootController" is kind of misleading, b/c UIWindow has a property rootViewController.
So to get this to work instead line [self.window addSubview:rootController.view]; you should do this self.window.rootViewController = self.rootController;
If you want to compare your code with a working code just create new project from template. Choose View-Based Application it has the schema you are looking for.
Open the TestViewController.xib and check whether any false outlets are connected there. Select the FilesOwner and go to connection inspector. The false outlets will be shown faded.. In this case, it would be label
Check your outlets in Interface Builder, you have something named "label" that does not exist. Remove the reference to this and you should be good to go.
again checkout....
use the connection inspector and write nib name and class name....in main View Controller.Xib

iPhone Loading Different Views

I have to xibs, and I want to load which one the user wants in the settings. I'm just working on actually loading them and how would this been done.
This is the function in the delegate which I think would be where this happens.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
This is the delegate header file.
#import <UIKit/UIKit.h>
#class myAppViewController;
#interface myAppAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
myAppViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet myAppViewController *viewController;
#end
So lets say I have a xib created called modernTheme, how would I load that or the myAppViewController. If someone could do this in a generic if statement, that would be great.
This looks like your viewController is being created 'in Interface Builder'. Instead of that you could create the ViewControllers yourself and add them dynamically. Your application:didFinishLaunchingWithOptions: could look something like this:
UIViewController *viewController;
if (showModernTheme) { // from your configuration
viewController = [[YourViewControllerA alloc] initWith…];
} else {
viewController = [[YourViewControllerB alloc] initWith…];
}
// assuming YourViewControllerA + B are inheriting from UIViewController
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
Hope that helps
–f