Default.png shows, but not for long - iphone

LOTS of Default.png Q's, but I didn't read one like this: I see Default.png, but then the screen goes blank, but no error messages, no abort. What am I missing?
SDK 4.3, iPhone only, no nib, no schemes, no orientation other than portrait up/down. Nav controller, 4 tabs.
App ABC works fine.
Clone XYZ doesn’t.
info.plist seems identical, including the half dozen icon files; neither app has an entry that contains “MainWindow.” Analyze and both generate “Build succeeded.” Run and both display “Attaching to process blah-blah-blah.” Any combo of reboot and/or restart Mac/XCode/simulator/device doesn’t do a dang thing. There is one difference, though: the drop-down for ABC shows the full device name, two 4.2’s and two 4.3’s; XYZ shows only “IOS Device” and the two 4.3’s. ABC shows all the NSLogs. XYZ shows none of them. And in both cases, the first NSLog is right after
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Clean all targets made no difference. I’m thinking, “Clone NOT.”
XJones, here's the code you requested. I've whacked it down as much as I could.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(#"app delegate CGRect");
CGRect frameMain = [UIScreen mainScreen].applicationFrame;
glbl_height = frameMain.size.height;
glbl_width = frameMain.size.width;
NSLog(#"app delegate background");
UIColor *blueGreenBackground = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"Default.png"]];
self.window.backgroundColor = blueGreenBackground;
[blueGreenBackground release];
NSLog(#"app delegate 3");
Method01_vc *method01VC = [[[Method01_vc alloc] init] autorelease];
// more controllers
method01VC.title = NSLocalizedString(#"Title 1, Method 1",#"(title 1)");
// more titles
UINavigationController *method01Nav = [[[UINavigationController alloc] initWithRootViewController:method01VC] autorelease];
// more controllers
NSLog(#"app delegate prior to tabBar init");
_tabBarController = [[UITabBarController alloc] init];
NSArray *sections = [NSArray arrayWithObjects:method01Nav, method02Nav, method03Nav, method04Nav, nil];
[_tabBarController setViewControllers:sections];
CGRect frame = CGRectMake(0.0, 0.0, 320, 48); // 48
UIView *tabBarView = [[UIView alloc] initWithFrame:frame];
[tabBarView setBackgroundColor:[UIColor colorWithRed:0.07 green:0.14 blue:0.04 alpha:0.8]];
NSArray *tabs = _tabBarController.viewControllers;
UIViewController *tab1 = [tabs objectAtIndex:0];
tab1.tabBarItem.image = [UIImage imageNamed:#"tabIcon01.png"];
tab1.tabBarItem.title = #"";
UIViewController *tab2 = [tabs objectAtIndex:1];
tab2.tabBarItem.image = [UIImage imageNamed:#"tabIcon02.png"];
tab2.tabBarItem.title = #"";
NSLog(#"app delegate prior to tabBar insert");
[[_tabBarController tabBar] insertSubview:tabBarView atIndex:0];
tabBarView.autoresizesSubviews = YES;
[tabBarView release];
_tabBarController.delegate = self;
[self.window addSubview:_tabBarController.view];
// self.tabBarController.selectedIndex = 1; ---- makes no difference
// self.window.rootViewController = self.tabBarController; --- ditto
NSLog(#"app delegate prior to makeKeyAndVisible");
[self.window makeKeyAndVisible];
NSLog(#"app delegate, about to return YES");
return YES;
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
NSLog(#"Method01 CGRect");
CGRect frameMain = [UIScreen mainScreen].applicationFrame;
UIView *view = [[UIView alloc] initWithFrame:frameMain];
self.view = view;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.autoresizesSubviews = YES;
After the above, all the usual labels and text fields follow.
Thanks again for taking the time to slog through it.
I've got my hopes set on a "Duh!"

Default.png is only displayed while iOS is launching your app. B/c your app doesn't do anything it launches very quickly so Default.png goes away and is replaced by the UI of your app. Either you are not adding a view to your apps window or the view you added displays as blank.
[EDIT 1: need to create a window]
Looked at your code and if you are not using IB you need to initialize the window in the app delegate before you add the tab bar controller's view to it.
self.window = [[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame] autorelease];
Here's a link to a blog that show's everything you need to do if not using IB:
http://code-dojo.blogspot.com/2009/11/build-iphone-application-without.html

Related

Parent view is not displayed after the low memory warning is received during MFMailCompose modal is open, canceled and draft saved/deleted

I have the following structure on my iPhone app
AppDelegate / UITabBarController / 5 UINavigationControllers(My tabs) / UIViewController(like rootViewController for each UINavigationController)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
HomeViewController *homeViewController = [[HomeViewController alloc] init];
GoalsTableViewController *goalsTableViewController = [[GoalsTableViewController alloc] init];
HistoryViewController *historyViewController = [[HistoryViewController alloc] init];
SettingsViewController *settingsViewController = [[SettingsViewController alloc] init];
InfoViewController *infoViewController = [[InfoViewController alloc] init];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
self.navBarActivity = [[UINavigationController alloc] initWithRootViewController:homeViewController];
self.navBarSettings = [[UINavigationController alloc] initWithRootViewController:settingsViewController];
self.navBarHistory = [[UINavigationController alloc] initWithRootViewController:historyViewController];
self.navBarGoals = [[UINavigationController alloc] initWithRootViewController:goalsTableViewController];
self.navBarAbout = [[UINavigationController alloc] initWithRootViewController:infoViewController];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.navBarActivity, self.navBarGoals, self.navBarHistory,self.navBarSettings, self.navBarAbout, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
In some UIViewControllers I implemented a MFMailComposeViewController in order to send emails.
I experimented a weird issue (reproduced on simulator and real devices iOS 5.0 and 5.1)...
Using an iPhone Simulator (only iOS 5.0 or 5.1), if I simulate a low memory warning while a MFMailComposerViewController modal is open on the screen and then tap on Cancel and then tap on Delete|Save draft, when the modal is dismissed the parent view seems not visible (blanked view).
The life cycle seems work fine due, if I follow the same steps but after simulate a low memory warning I send the email from MFMailComposeViewController modal, when modal is dismissed, my parent view looks fine.
Any suggestions how to prevent my parent view from being unloaded on memory warning?
Edit1
I figured out what is happening, after unloading and comeback to the view and entering the last view within viewdidload(life cycle), the tabBar is not inserting navigation view. I check the subviews of tabBar:
UITransitionView
==><UIViewControllerWrapperView>
==> empty
<UITabBar>
I reintegrated the view of navigationBar by adding as subview in viewdidload:
UIView *tabBarControllerWrapperView = [[[self.tabBarController.view.subviews objectAtIndex:0] subviews] objectAtIndex:0];
// tabBar UIViewControllerWrapperView has not views
if([tabBarControllerWrapperView.subviews count] == 0)
{
// add navigationbar view
[tabBarControllerWrapperView addSubview:self.navigationController.view];
}
There is no better way to fix it, any thoughts?
After a memory warning is possible that on the non visible controllers is called viewDidUnload (iOS <= 5 ).In your case the view of the controller that presented the modal mailcomposer was probably unloaded.
The idea behind viewDidUnload is that you save the data you need to restore the view once viewDidLoad is called again. What you have to keep in mind is that your viewDidLoad can be called multiple times.
On iOS6 viewDidUnload is not called anymore, so this logic must be moved to didReceiveMemoryWarning

UITabBarController Does not shows tabbarItems name

I am creating app based on UTabbarController. I have creates that tab bar programmatically. Everything is running fine except I can not see the tabBatItem title. I have initialized everything properly, but when application launches all I can see is the first tabbar title. but if I select 2nd tabbaritem or so on I can see their names. I don't know whats going wrong here. Here is my code. Please let me know if I made any mistake.
Thanks.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
HomeViewController *viewController1 = [[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
UINavigationController*navController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
navController1.title=#"Home";
[viewController1 release];
TrainerTableViewController *viewController2 = [[TrainerTableViewController alloc] initWithNibName:#"TrainerTableViewController" bundle:nil];
UINavigationController*navController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
navController1.title=#"Trainer";
[viewController2 release];
SettingsTableViewController *viewController8 = [[[SettingsTableViewController alloc] initWithNibName:#"SettingsTableViewController" bundle:nil] autorelease];
UINavigationController*navController8=[[[UINavigationController alloc]initWithRootViewController:viewController8]autorelease];
navController1.title=#"Settings";
AboutUsViewController *viewController9 = [[[AboutUsViewController alloc] initWithNibName:#"AboutUsViewController" bundle:nil] autorelease];
UINavigationController*navController9=[[[UINavigationController alloc]initWithRootViewController:viewController9]autorelease];
navController1.title=#"About Us";
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController1, navController2,navController8, navController9, nil];
[navController1 release];
[navController2 release];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
You can do this by including the code below inside the .m file of the view controller for each tab bar item. The code also includes how to change the image on the tab bar.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
self.title = #"Apply Now";
self.tabBarItem.image = [UIImage imageNamed:#"tbApplyNow.png"];
}
return self;
}
The best way to solve this problem is to set title of viewController not of navigationController
viewController1.tabBarItem.title = #"CohesiveSelf";
Do this for all tabs.
You're only setting the title for navController1. For each nab controller you create you need to set the title for that one.
Try this:
CHANGE:
navController1.title=#"Trainer";
TO
navController2.title=#"Trainer";
CHANGE:
navController1.title=#"Settings";
TO
navController8.title=#"Settings";
CHANGE:
navController1.title=#"About Us";
TO
navController9.title=#"About Us";
Also not you are not releasing navController8 or 9 which will cause in a memory leak
You are actually setting the title for the NavigationControllers. Also, watch that your code sets the title of navController1 multiple times, rather than setting it for the others.
You can set the titles for your tabBar by setting up tabBarItems for each controller.
You have the option of subclassing, or just including this in the application:didFinishLaunchingWithOptions: method in your AppDelegate.
Here's an example:
UITabBarItem *tbi1 = [navController1 tabBarItem];
[tbi1 setTitle:#"Home"];
UIImage *i1 = [UIImage imageNamed:#"hometabicon.png"];
[tbi1 setImage:i1];
This will set the title of tab1 to 'Home' and will set the tabBar icon to a file named 'hometabicon.png'.
You can repeat the same pattern for each of the other tabs.

Two switches in a window on iPhone

I've just started learning how to develop an iPhone app.
I'm trying to make an app with two switches. I made two classes (Switch1 & Switch2).
First, I tested the app with one switch (Switch1), and the app worked. But when I made the second class (Switch2) and I Build/Run the app, the first switch (Switch1) disappeared, and what I saw just the second switch (Switch2).
After that I made the background of the (Switch1 & Switch2) celarColor, I could see both of switches. However, the first switch (Switch1) can't be switched.
so I think my problem is how to make both switches (Switch1 & Switch2) visible and working at the same time in the "window"
The question (could be stupid): What can I make them visible and working at the same time?
I think the problem in the following code: This is from the AppDelegate
UIScreen *s1 = [UIScreen mainScreen];
view1 = [[Switch1 alloc] initWithFrame: s1.applicationFrame];
window = [[UIWindow alloc] initWithFrame: s1.bounds];
[window addSubview: view1];
[window makeKeyAndVisible];
UIScreen *s2 = [UIScreen mainScreen];
view2 = [[Switch2 alloc] initWithFrame: s2.applicationFrame];
window = [[UIWindow alloc] initWithFrame: s2.bounds];
[window addSubview: view2];
[window makeKeyAndVisible];
return YES;
Here is the Switch1.h
#import
#interface Switch1 : UIView {
UISwitch *mySwitch1;
}
#property (nonatomic, retain) IBOutlet UISwitch *mySwitch1;
#end
Here is the Switch1.m
#import "Switch1.h"
#implementation Switch1
#synthesize mySwitch1;
- (id) initWithFrame: (CGRect) frame {
if ((self = [super initWithFrame: frame])) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
mySwitch1 = [[UISwitch alloc] initWithFrame: CGRectZero];
if (mySwitch1 == nil) {
[self release];
return nil;
}
mySwitch1.on = NO; //the default
[mySwitch1 addTarget: [UIApplication sharedApplication].delegate
action: #selector(valueChanged:)
forControlEvents: UIControlEventValueChanged
];
CGRect b1 = self.bounds;
mySwitch1.transform = CGAffineTransformMakeScale(2, 2);
mySwitch1.center = CGPointMake(
b1.origin.x + b1.size.width / 2,
b1.origin.y + b1.size.height / 2
);
[self addSubview: mySwitch1];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void) drawRect: (CGRect) rect {
// Drawing code
}
*/
- (void) dealloc {
[mySwitch1 release];
[super dealloc];
}
#end
You might want to configure a view controller with a view and then toss your two switches on that first. Do you understand the MVC patterns here: https://developer.apple.com/library/ios/#documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html
and here's the view controller guide: https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html.
When you're initializing with UIScreen, you're making both switches the same size (the window size) and thus switch 2 is over switch 1 since it's initialized second.
So you are adding one screen (s2) on top of another screen (s1) and therefore you are not able to access s1. You need to make the size of s2 and s1 smaller so that they do not take the whole screen size.
Also by saying makeKeyAndVisible you make the window visible and able to accept user interaction. No need to say that twice.
You're resetting the window when you call
window = [[UIWindow alloc] initWithFrame: s2.bounds];
s1 isn't there anymore because you've created a new window over it. You could just do
UIScreen *s1 = [UIScreen mainScreen];
window = [[UIWindow alloc] initWithFrame: s1.bounds];
view1 = [[Switch1 alloc] initWithFrame: s1.applicationFrame];
view2 = [[Switch2 alloc] initWithFrame: s2.applicationFrame];
[window addSubview: view1];
[window addSubview: view2];
[window makeKeyAndVisible];
return YES;
If you're just starting, definitely check out this tutorial on iPhone dev. It shows how to use UIViewController, UIView, and a lot of the supplied classes for the iPhone like UITableView and UIImageView.

UIActivityIndicatorView is not working (getting Facebook permissions affecting UIActivityIndicatorView)

I have a tabbarcontroller with three tabs/viewcontrollers.
When I first start my app, with my ActivityIndicator set to be visible and animated - courtesy of interface builder - it works fine.
However when I click a button an internet window opens to Facebook in order to get the user's permission.
Once the Facebook part is taken care it returns to my app but the ActivityIndicator is not longer animated - it is still visible though, just frozen.
If I switch to another tab/viewcontroller and then come back to the tab/viewcontroller with the ActivityIndicator everything works fine.
Is there a way to refresh my ViewController so that I don't have to programmatically make the ViewController switch back and forth? Or any other suggestions?
/* I searched the forums and I saw a similar question. It appeared that there was a broken connection. Therefore I'll include the code where I add the ViewController (i.e., "controller" to my tabbarcontroller). */
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
controller = [[DemoAppViewController alloc] init];
controller.view.frame = CGRectMake(0, 20, 320, 460);
controller.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"movieAppBackground.jpg"]];
MyTabBarViewController *vc2 = [[MyTabBarViewController alloc] init];
SecondViewController *vc3 = [[SecondViewController alloc] init];
controller.title = #"Intro Screen";
vc2.title = #"Explore";
vc3.title = #"Send a Pic";
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = [NSArray arrayWithObjects:controller, vc2, vc3, nil];
self.theTBC=tbc;
[controller release];
[vc2 release];
[vc3 release];
[tbc release];
[self.window addSubview:tbc.view];
[self.window makeKeyAndVisible];
return YES;
}
whereever u have used NIB file to show with viewcontrollers u have to create them with initwithname
Example
SecondViewController *r=[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
like this change whereever u have used nib file to create instance,
i meaned for all custom viewcontrollers u have created with NIB file

How to show UINavigationController on view

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:#"MainPage" bundle:nil];
UINavigationController *nav_obj = [[UINavigationController alloc] initWithRootViewController:overviewViewController ];
[self.viewController presentModalViewController:nav_obj animated:YES];
[overviewViewController release];
[self.window makeKeyAndVisible];
return YES;
}
This code shows the blue bar of navigation controller, but no buttons on it.It seems like to be that the UINavigationController allocated as empty.
Who knows what problems is?
UPD:Archive http://www.mediafire.com/?lbjjvl6fcue2q18
Please help me, I'm new in objective-c
You need to create the button for it, for example:
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:launcherView action:#selector(endEditing)];
self.navigationItem.leftBarButtonItem = doneButton;
[doneButton release];
The correct way to use a UINavigationController is to push view controllers on to it. That way they will be stacked and the navigation bar will be populated with a back button when it is case (i.e., when you can actually go back to a previous controller). You control the label that appears in the "back" button by defining the title of the controllers you push.
The technique shown in another answer (setting explicitly the button) is useful with defining the right button, if you ever need one.
You could try with this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:#"MainPage" bundle:nil];
UINavigationController* navigation = [[UINavigationController alloc] init];
[navigation pushViewController:overviewViewController animated:NO];
[overviewViewController release];
[window addSubview:[navigation view]];
[self.window makeKeyAndVisible];
return YES;
}
Instead of doing:
UINavigationController* navigation = [[UINavigationController alloc] init];
[navigation pushViewController:overviewViewController animated:NO];
you could also use initWithRootController, but to display the general case of how you push a view controller I preferred this one.
Notice that since you are pushing just a root controller, you should see no back button at the moment, but if you push a second view controller, then it will appear.
EDIT: I gave a look at your project. Summary of what you should try and do:
objects you need in your NIB: File's Owner (UIApplication), First Responder, FBFun App Delegate (iVkAppDelegate), Window (UIWindow); remove the rest;
File's owner delegate outlet is FBFun App Delegate;
FBFun App Delegate window outlet is Window.
With this simple setup (more or less what you have), use this code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController* navigation = [[UINavigationController alloc] init];
//-- MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:#"MainPage" bundle:nil];
iVkViewController *overviewViewController = [[iVkViewController alloc] init];
overviewViewController.title = #"First";
[navigation pushViewController:overviewViewController animated:NO];
iVkViewController *overviewViewController2 = [[iVkViewController alloc] init];
overviewViewController2.title = #"Second";
[navigation pushViewController:overviewViewController2 animated:NO];
[overviewViewController release];
[window addSubview:[navigation view]];
[self.window makeKeyAndVisible];
return YES;
}
In the code above, as you notice, I instantiated twice your iVkViewController just to have a second controller to push onto the navigator.
Please, delete your existing app from the simulator, and the run this in order to see that the navigation bar is correctly created and you can go back from the second controller to the first one.
I removed usage of MainPageDialog, because the MainPage nib has many problems.
But I hope this skeleton is sufficient for you to go forward with your development.
You had missed the line as you are not adding view to window.Add this line in your code
[window addSubview:nav_obj.view];