I've done some research about my problem without fining a solution. My project compiles with success and launches but but the simulator only shows black. My project was working perfectly before I added googles Interstitials to my app. The following is my code to implement this:
Appdelegate.h
#interface AppDelegate : UIResponder <UIApplicationDelegate,GADInterstitialDelegate> {
UIWindow *window_;
MainViewController *mainController;
GADInterstitial *splashInterstitial_;
}
#property (nonatomic, retain) UIWindow *window;
#property(nonatomic, retain) IBOutlet MainViewController *mainController;
#property(nonatomic, readonly) NSString *interstitialAdUnitID;
- (GADRequest *)createRequest;
Appdelegate.m
#define INTERSTITIAL_AD_UNIT_ID #""
#synthesize mainController = mainViewController_;
#synthesize window = window_;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window setRootViewController:mainViewController_];
[self.window makeKeyAndVisible];
splashInterstitial_ = [[GADInterstitial alloc] init];
splashInterstitial_.adUnitID = self.interstitialAdUnitID;
splashInterstitial_.delegate = self;
[splashInterstitial_ loadAndDisplayRequest:[self createRequest]
usingWindow:self.window
initialImage:[UIImage imageNamed:#"InitialImage"]];
}
- (void)dealloc {
splashInterstitial_.delegate = nil;
}
- (NSString *)interstitialAdUnitID {
return INTERSTITIAL_AD_UNIT_ID;
}
#pragma mark GADRequest generation
- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
request.testDevices =
[NSArray arrayWithObjects:
nil];
return request;
}
MainViewController.h
#interface MainViewController : UIViewController <GADInterstitialDelegate> {
UIButton *interstitialButton_;
GADInterstitial *interstitial_;
}
#property (nonatomic, retain) GADInterstitial *interstitial;
#property (nonatomic, retain) IBOutlet UIButton *interstitialButton;
- (IBAction)showInterstitial:(id)sender;
MainViewController.m
#synthesize interstitialButton = interstitialButton_;
#synthesize interstitial = interstitial_;
- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
// Alert the error.
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"GADRequestError"
message:[error localizedDescription]
delegate:nil cancelButtonTitle:#"Drat"
otherButtonTitles:nil] ;
[alert show];
interstitialButton_.enabled = YES;
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
[interstitial presentFromRootViewController:self];
interstitialButton_.enabled = YES;
}
- (IBAction)showInterstitial:(id)sender {
self.interstitial = [[GADInterstitial alloc] init] ;
self.interstitial.delegate = self;
AppDelegate *appDelegate =
(AppDelegate *)
[UIApplication sharedApplication].delegate;
self.interstitial.adUnitID = appDelegate.interstitialAdUnitID;
[self.interstitial loadRequest: [appDelegate createRequest]];
interstitialButton_.enabled = NO;
}
Related
How to show GADInterstitial in ios project? i am getting error "Request error : no ads to show" but admob is working in my another project.
// ViewController.h
#import <UIKit/UIKit.h>
#import "GADBannerView.h"
#import "GADCustomEventBanner.h"
#import "GADInterstitial.h"
#interface ViewController : UIViewController <GADInterstitialDelegate>
{
UIButton *interstitialButton_;
GADInterstitial *interstitial_;
}
#property(nonatomic, retain) IBOutlet UIButton *interstitialButton;
#property(nonatomic, retain) GADInterstitial *interstitial_;
- (IBAction)showInterstitial:(id)sender;
#end
//ViewController.h
#import "ViewController.h"
#implementation ViewController
#synthesize interstitialButton ;
#synthesize interstitial_;
- (void)dealloc {
interstitial_.delegate = nil;
[interstitial_ release];
[interstitialButton_ release];
[super dealloc];
}
- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
// Alert the error.
UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:#"GADRequestError"
message:[error localizedDescription]
delegate:nil cancelButtonTitle:#"Drat"
otherButtonTitles:nil] autorelease];
[alert show];
interstitialButton_.enabled = YES;
}
-(void)interstitialWillPresentScreen:(GADInterstitial *)ad{
NSLog(#"on screen");
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
[interstitial presentFromRootViewController:self];
interstitialButton_.enabled = YES;
[self showInterstitial:nil];
}
- (IBAction)showInterstitial:(id)sender {
self.interstitial_ = [[[GADInterstitial alloc] init] autorelease];
self.interstitial_.delegate = self;
self.interstitial_.adUnitID = MY_ADMOB_KEY; // this key is working in admob //
GADRequest *request = [GADRequest request];
request.testing = YES;
[self.interstitial_ loadRequest: request];
interstitialButton_.enabled = NO;
}
#end
Change the ad size to full screen in the settings in admob website.
self.interstitial_.adUnitID = MY_ADMOB_KEY; // this key is working in admob
check this comment, and replace it with:
self.interstitial_.adUnitID = #"ca-app-pub-xxxxxxxxxxx"; // this key is working in admob
you should get you own adUnitID form admob
I have a problem with my app (ipad) on iOS4. The Keyboard doesn't work, doesn't display on my webview AFTER the first view (login view).
Appdelagate :
AppDelegate.h
#class RootViewController;
#interface StandardFacileAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RootViewController *rootViewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
rootViewController = [[RootViewController alloc] init];
window.rootViewController = rootViewController;
//[window addSubview:rootViewController.view];
[window makeKeyAndVisible];
return YES;
}
RootViewController :
- (void)viewDidLoad {
[super viewDidLoad];
[self loadViewController];
[self.view addSubview:viewController.view];
}
- (void)loadViewController {
ViewController *viewControllertemp = [[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
self.viewController = viewControllertemp;
[viewControllertemp release];}
viewController is my login view after request i call the method for change the view (my webview) :
- (void)changeViewToIpadTheWebView:(UIViewController *)fromView{
UIViewController *currentView = (UIViewController*)fromView;
NSLog(#"currentView =>%#",currentView);
if(!ipadTheWebView)
[self loadipadTheWebView];
[currentView.view removeFromSuperview];
for (UIView *view in [self.view subviews]) {
[view removeFromSuperview];
}
[self.view addSubview:ipadTheWebView.view];
NSURL *url = [NSURL URLWithString:#"http://www.google.com/"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[ipadTheWebView.webView loadRequest:requestURL];
My webview is ok but if i want search word in google, the keyboard doesn't display (the view scroll) when the textfield have the focus.
What is the problem, this code working on iOS5 but not ios4?
Thanks for your help ;)
Edit :
Thanks Mathieu,
RootViewController.h
#import <UIKit/UIKit.h>
#class ViewController;
#class IpadTheWebView;
#interface RootViewController : UIViewController {
ViewController *viewController;
IpadTheWebView *ipadTheWebView;
}
#property (nonatomic,retain) ViewController *viewController;
- (void)loadViewController;
- (void)changeViewToViewController:(UIViewController *)fromView;
#property (nonatomic,retain) IpadTheWebView *ipadTheWebView;
- (void)loadipadTheWebView;
- (void)changeViewToIpadTheWebView:(UIViewController *)fromView;
- (void)keyboardWillShow:(NSNotification *)notification;
- (void)keyboardWillHide:(NSNotification *)note;
#end
In my custom Tab Bar Application, the orientation never seems to change, even if I force rotate the status bar. Here is my code in my AppDelegate:
AppDelegate.h:
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
#class exampleViewContoller;
#class example1ViewController;
#class example2ViewController;
#class example3ViewController;
#class example4ViewController;
#interface <appname>AppDelegate : NSObject <UIApplicationDelegate, MBProgressHUDDelegate> {
UIWindow *window;
UITabBarController *rootController;
exampleViewContoller *viewController;
example1ViewController *viewController1;
example2ViewController *viewController2;
example3ViewController *viewController3;
example4ViewController *viewController4;
NSMutableData *responseData;
NSMutableArray *tweets;
MBProgressHUD *HUD;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#property (nonatomic, retain) IBOutlet exampleViewContoller *viewController;
#property (nonatomic, retain) IBOutlet example1ViewController *viewController1;
#property (nonatomic, retain) IBOutlet example2ViewController *viewController2;
#property (nonatomic, retain) IBOutlet example3ViewController *viewController3;
#property (nonatomic, retain) IBOutlet example4ViewController *viewController4;
#property (nonatomic, retain) NSMutableArray *tweets;
#end
AppDelegate.m:
#import "<appname>AppDelegate.h"
#import "exampleViewContoller.h"
#import "example1ViewController.h"
#import "example2ViewController.h"
#import "example3ViewController.h"
#import "example4ViewController.h"
#import "SBJson.h"
#define TMP NSTemporaryDirectory()
#implementation <appname>AppDelegate
#synthesize window = _window;
#synthesize rootController;
#synthesize viewController;
#synthesize viewController1;
#synthesize viewController2;
#synthesize viewController3;
#synthesize viewController4;
#synthesize tweets;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGFloat width = self.rootController.view.bounds.size.width;
CGFloat height = self.rootController.view.bounds.size.height;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, height)];
UIImage *imageView = [UIImage imageNamed:#"TabBarBackground.png"];
UIColor *kMainColor = [[UIColor alloc] initWithPatternImage:imageView];
[v setBackgroundColor:kMainColor];
[kMainColor release];
[self.rootController.tabBar insertSubview:v atIndex:0];
[imageView release];
[v release];
responseData = [[NSMutableData data] retain];
tweets = [NSMutableArray array];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:#"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=ENTER_USER_HERE&count=20"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSAssert(nil != self.rootController, #"tab bar controller not hooked up!");
BOOL iPad = NO;
#ifdef UI_USER_INTERFACE_IDIOM
iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#endif
if (iPad) {
self.viewController = [[[exampleViewContoller alloc] initWithNibName:#"exampleViewController_iPad" bundle:nil] autorelease];
self.viewController1 = [[example1ViewController alloc] initWithNibName:#"example1ViewController_iPad" bundle:nil] autorelease];
self.viewController2 = [[[example2ViewController alloc] initWithNibName:#"example2ViewController_iPad" bundle:nil] autorelease];
self.viewController3 = [[[example3ViewController alloc] initWithNibName:#"example3ViewController_iPad" bundle:nil] autorelease];
self.viewController4 = [[[example4ViewController alloc] initWithNibName:#"example4ViewController_iPad" bundle:nil] autorelease];
} else {
self.viewController = [[[exampleViewContoller alloc] initWithNibName:#"exampleViewContoller_iPhone" bundle:nil] autorelease];
self.viewController1 = [[[example1ViewController alloc] initWithNibName:#"example1ViewController_iPhone" bundle:nil] autorelease];
self.viewController2 = [[[example2ViewController alloc] initWithNibName:#"example2ViewController2_iPhone" bundle:nil] autorelease];
self.viewController3 = [[[example3ViewController alloc] initWithNibName:#"example3ViewController_iPhone" bundle:nil] autorelease];
self.viewController4 = [[[example4ViewController alloc] initWithNibName:#"example4ViewController_iPhone" bundle:nil] autorelease];
}
self.rootController.viewControllers = [NSArray arrayWithObjects:self.viewController, self.viewController4, self.viewController1, self.viewController3, self.viewController2, nil];
[viewController release];
[viewController1 release];
[viewController2 release];
[viewController3 release];
[viewController4 release];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
self.window.rootViewController = self.rootController;
#else
[self.window addSubview:rootController.view];
#endif
[self.window makeKeyAndVisible];
HUD = [[MBProgressHUD alloc] initWithView:viewController.view];
[viewController.view addSubview:HUD];
[HUD show:NO];
HUD.delegate = self;
HUD.labelText = #"Loading";
return YES;
}
//[---CODE CLIP---]
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation {
CGFloat width = self.rootController.view.bounds.size.width*2;
CGFloat height = self.rootController.view.bounds.size.height;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, height)];
UIImage *imageView = [UIImage imageNamed:#"TabBarBackground.png"];
UIColor *kMainColor = [[UIColor alloc] initWithPatternImage:imageView];
[v setBackgroundColor:kMainColor];
[kMainColor release];
[self.rootController.tabBar insertSubview:v atIndex:0];
[imageView release];
[v release];
}
- (void)hudWasHidden {
[HUD removeFromSuperview];
}
//[---CODE CLIP---]
- (void)dealloc
{
[_window release];
[rootController release];
[HUD release];
[super dealloc];
}
#end
The problem is that when I rotate the device in iOS Simulator, the application won't rotate. Any ideas would be much appreciated!
UPDATE
I have also noticed that the launch image is also not rotating (for iPad that is - iPhone doesn't do landscape launch images).
NOTE FOR JMANS
I overrode UITabBarController:
#implementation UITabBarController (MyApp)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if(self.selectedIndex==4)
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
else
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
I would start by including this in all of your view controllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Also, make sure that you are supporting multiple orientations in your Info.plist.
Tab Bar Controllers and View Rotation
Tab bar controllers support a portrait orientation by default and do not rotate to a landscape orientation unless all of the contained view controllers support such an orientation. When a device orientation change occurs, the tab bar controller queries its array of view controllers. If any one of them does not support the orientation, the tab bar controller does not change its orientation.
(I'm beginner.)
I'm practicing Navigation Controller. I try to implement a simple calculator.
I ran the code in simulator. After I pressed any button which was linked to "addFunction", "substractFunction", "multiplyFunction" or "divideFunction", It crashed.
The debugger marked the following code in main.m
int retVal = UIApplicationMain(argc, argv, nil, nil);
and said "Thread 1: Program received signal: "SIGABRT"."
Does anyone know how to cope with this situation? Thanks.
Here's the code:
ChangeAppView.h:
#import <UIKit/UIKit.h>
#class ChangeViewController;
#interface ChangeAppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
UINavigationController *navigationController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) UINavigationController *navigationController;
#end
ChangeAppDelegate.m:
#import "ChangeAppDelegate.h"
#import "ChangeViewController.h"
#implementation ChangeAppDelegate
#synthesize window;
#synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
navigationController = [[UINavigationController alloc] init];
self.window.rootViewController = navigationController;
ChangeViewController *changeViewController = [[ChangeViewController alloc] initWithNibName:#"ChangeViewController" bundle:nil];
[navigationController pushViewController:changeViewController animated:YES];
[changeViewController release];
[self.window makeKeyAndVisible];
return YES;
}
…
- (void)dealloc
{
[navigationController release];
[window release];
[super dealloc];
}
#end
CalculatorViewController.h:
#import <UIKit/UIKit.h>
#interface CalculatorViewController : UIViewController
{
IBOutlet UITextField *numberField1;
IBOutlet UITextField *numberField2;
IBOutlet UILabel *resultLabel;
}
#property (nonatomic , retain) IBOutlet UITextField *numberField1;
#property (nonatomic , retain) IBOutlet UITextField *numberField2;
#property (nonatomic , retain) IBOutlet UILabel *resultLabel;
-(IBAction)addFunction:(id)sender;
-(IBAction)substractFunction:(id)sender;
-(IBAction)multiplyFunction:(id)sender;
-(IBAction)divideFunction:(id)sender;
-(IBAction)clear:(id)sender;
-(IBAction)backgroundTap:(id)sender;
#end
CalculatorViewController.m:
#import "CalculatorViewController.h"
#implementation CalculatorViewController
#synthesize numberField1;
#synthesize numberField2;
#synthesize resultLabel;
-(IBAction)addFunction:(id)sender
{
float a = ([numberField1.text floatValue]);
float b = ([numberField2.text floatValue]);
resultLabel.text = [NSString stringWithFormat:#"%2.f" , a+b];
}
-(IBAction)substractFunction:(id)sender
{
float a = ([numberField1.text floatValue]);
float b = ([numberField2.text floatValue]);
NSString *result = [[NSString alloc] initWithFormat:#"%2.f" , a-b];
resultLabel.text = result;
[result release];
}
-(IBAction)multiplyFunction:(id)sender
{
float a = ([numberField1.text floatValue]);
float b = ([numberField2.text floatValue]);
resultLabel.text = [[NSString alloc] initWithFormat:#"%2.f" , a*b];
}
-(IBAction)divideFunction:(id)sender
{
float a = ([numberField1.text floatValue]);
float b = ([numberField2.text floatValue]);
resultLabel.text = [[NSString alloc] initWithFormat:#"%2.3f" , a/b];
}
-(IBAction)clear:(id)sender
{
numberField1.text = #"";
numberField2.text = #"";
resultLabel.text = #"";
}
-(IBAction)backgroundTap:(id)sender
{
[numberField1 resignFirstResponder];
[numberField2 resignFirstResponder];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[numberField1 release];
[numberField2 release];
[resultLabel release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
self.title = #"Calculator";
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
From the exception above, it seems that your IBActions are not properly connected.
As dasdom mentioned, delete all your buttons, create new buttons and then add IBAction methods accordingly.
Also one more thing i recognized in your code, in the multiply and divide methods there is a memory leak.You have written
resultLabel.text = [[NSString alloc] initWithFormat:#"%2.f" , a*b];
it should be
resultLabel.text = [[[NSString alloc] initWithFormat:#"%2.f" , a*b]autorelease];
or
resultLabel.text = [NSString StringWithFormat:#"%2.f" , a*b];
and do a similar change in divide method also.
To what did you link your backgroundtap method?
It seems that you buttons aren't buttons. They seem to be view. Delete the buttons from you nib and put new buttons there and link them you our IBActions.
The Tabs in my Tab Bar don't seem to be showing up. Here is my App Delegate code:
(appname)AppDelegate.h:
#import <UIKit/UIKit.h>
#class TwitterViewContoller;
#interface <appname>AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *rootController;
TwitterViewContoller *viewController;
NSMutableData *responseData;
NSMutableArray *tweets;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#property (nonatomic, retain) IBOutlet TwitterViewContoller *viewController;
#property (nonatomic, retain) NSMutableArray *tweets;
#end
(appname)AppDelegate.m:
#import "<appname>AppDelegate.h"
#import "TwitterViewContoller.h"
#import "SBJson.h"
#implementation <appname>AppDelegate
#synthesize window = _window;
#synthesize rootController;
#synthesize viewController;
#synthesize tweets;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
CGFloat width = self.rootController.view.bounds.size.width;
CGFloat height = self.rootController.view.bounds.size.height;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, height)];
UIImage *imageView = [UIImage imageNamed:#"TabBarBackground.png"];
UIColor *kMainColor = [[UIColor alloc] initWithPatternImage:imageView];
[v setBackgroundColor:kMainColor];
[kMainColor release];
[self.rootController.tabBar insertSubview:v atIndex:0];
[imageView release];
[v release];
responseData = [[NSMutableData data] retain];
tweets = [NSMutableArray array];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:#"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=USER_NAME_ID"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSAssert(nil != self.rootController, #"tab bar controller not hooked up!");
self.viewController = [[[TwitterViewContoller alloc] initWithNibName:#"TwitterViewContoller_iPhone" bundle:nil] autorelease];
self.rootController.viewControllers = [NSArray arrayWithObject:self.viewController];
// this is now the Right Way to set the root view for your app, in iOS 4.0 and later
self.window.rootViewController = self.rootController;
[self.window makeKeyAndVisible];
return YES;
}
#pragma mark NSURLConnection delegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSArray *allTweets = [responseString JSONValue];
[viewController setTweets:allTweets];
}
- (void)dealloc {
[_window release];
[rootController release];
[viewController release];
[super dealloc];
}
#end
I believe the problem is in application didFinishLaunchingWithOptions: as the only recent changes I have made to App Delegate have been these lines:
NSAssert(nil != self.rootController, #"tab bar controller not hooked up!");
self.viewController = [[[TwitterViewContoller alloc] initWithNibName:#"TwitterViewContoller_iPhone" bundle:nil] autorelease];
self.rootController.viewControllers = [NSArray arrayWithObject:self.viewController];
// this is now the Right Way to set the root view for your app, in iOS 4.0 and later
self.window.rootViewController = self.rootController;
[self.window makeKeyAndVisible];
(EDIT: removing the 2nd and 3rd line above fixes the problem but I need to have them). Any ideas?
Make a Property of your other ViewControllers and synthesize them in your implementation file (.m). Also import them in your AppDelegate.m file. Here is what your header (.h) file will look like (rootController is your TabBarController):
#import <UIKit/UIKit.h>
#class TwitterViewContoller;
#class OtherViewController;
#interface <appname>AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *rootController;
TwitterViewContoller *viewController;
OtherViewController *viewController1;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootController;
#property (nonatomic, retain) IBOutlet TwitterViewContoller *viewController;
#property (nonatomic, retain) IBOutlet OtherViewController *viewController1;
#end
And the first few lines of your implementation (.m) file:
#import "<appname>AppDelegate.h"
#import "TwitterViewContoller.h"
#import "OtherViewController.h"
#implementation <appname>AppDelegate
#synthesize window = _window;
#synthesize rootController;
#synthesize viewController;
#synthesize viewController1;
Add additional allocs and inits for all your ViewControllers:
self.viewController = [[[TwitterViewContoller alloc] initWithNibName:#"TwitterViewContoller_iPhone" bundle:nil] autorelease];
self.viewController1 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController_iPhone" bundle:nil] autorelease];
Then replace this:
self.rootController.viewControllers = [NSArray arrayWithObject:self.viewController];
with this:
self.rootController.viewControllers = [NSArray arrayWithObjects:self.viewController, self.viewController1, nil];
This is so you can add more than one UIViewController to your TabBar Controller.
Then of course, release:
[viewController release];
[viewController1 release];
And under each class for your ViewControllers, under the -initWithNibName method add this inside the if (self) statement:
UITabBarItem *tabBarItem = [self tabBarItem];
UIImage *tabBarImage = [UIImage imageNamed:#"IMAGE NAME.png"];
[tabBarItem setImage:tabBarImage];
[tabBarItem setTitle:#"TITLE GOES HERE"];
Run your application and it should be working now!