Loading xib dynamically but wrong one displaying - iphone

I have an universal app that I am trying to share a viewController code with. I have this:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
AboutController *screen = [[AboutController alloc] initWithNibName:#"iPhoneAboutController" bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
}
else
{
AboutController *screen = [[AboutController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
}
Although this is loading, and when I step through the code, it does hit the xib for the iPhone but it seems to always be loading the iPad version. I know this because in the xib file for the iPhone, I have manually added different background images and it never shows. In the iPhone simulator it shows the iPad version where it is off screen.
Also, if I step through the code in the controller, it does show that the load is the iPhone yet display is all iPad objects. In the iPhone xib, I do have the Files Owner set to the AboutController.
This is the first time I am attempting to "share code". I know I can just create separate class files with the same code but this seems senseless. Any help is greatly appreciated.
Geo...

For starters: make sure you don't override nib initialization in your AboutController.
If not, try cleaning your project (also delete your app's folders in ~/Library/Developer/Xcode/DerivedData). Also uninstall the app from device and then rebuild.

Related

Auto-resize iPhone xib app to ipad

I built an iPhone app "using xib" with 5-6 screens. Now I want to auto-resize the display for iPad. I am using xcode 4.6.
Do I have to rebuild the entire code using storyboards? It will be a very tedious work. Is there any solution for this?
You'll need to create only new xib files for iPad and name them as ViewController_iPhone.xib and ViewController_iPad.xib and when switching your views, just put a simple condition
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
ViewController *viewController = [[ViewController alloc] initWithNibName:
#"ViewController_iPad" bundle:nil];
} else {
ViewController *viewController = [[ViewController alloc] initWithNibName:
#"ViewController_iPhone" bundle:nil];
}
use autolayout and everything will be done automatically
if not autolayout, then making 2 xib will be a better option. Make ipad size xib with the same name and put ~ipad after classname.
Like if you xib name is myClass.xib and create other one like myClass~ipad.xib.

pushViewController Not Working on iOS 5 (OK on iOS 6)

I have a UINavigationController that displays several buttons on screen. They all simply use the line:
myViewController *newView = [[myViewController alloc] initWithNibName:#"myViewController"
bundle:nil];
[[self navigationController] pushViewController:newView animated:YES];
to transition to the next view. I have one such view controller however that results in a crash at this very line ONLY on iOS 5. It works perfectly fine on iOS 6. I am baffled. There are no real details to the crash. It is a SIGABRT that highlights the main.m line:
exitStatus = UIApplicationMain( argc, argv, nil, NSStringFromClass([ApplicationDelegate class]));
I have no clue...
You Need to unCheck the Auto Layout.
And make sure you are changing here also.. select ios 5.1
Try this line:
myViewController *newView = [[myViewController alloc] initWithNibName:#"myViewController"
bundle:[NSBundle mainBundle]];
in place of:
myViewController *newView = [[myViewController alloc] initWithNibName:#"myViewController"
bundle:nil];
I have experimented a similar issue an here are the steps that I feel need to be considered:
(if you are using xib file) like Venkat Manohar Perepa mentioned, check that Use Auto Layout is turned off as it is an iOS 6 specific feature.
(if you are using xib file) look at the content of the xib file that is used when presenting your viewcontroller and check that there is no class that are iOS6 specific (e.g: NSLayoutConstraint)
Last (and that was the issue I was facing) you should check if the crash appear on a device that has iOS5 installed. If it doesn't but still crash on the simulator remove the application you have installed by choosing iPhone Simulator > Reset Content and Settings.

App wont start using testflight on iOS6

I have an application that I want to test it on iOS device. The application uses NIB files and no story board.
Target framework is set to - 5.1
Device - Universal.
I have created the IPA file and uploaded to TestFlightApp.
I have downloaded and installed the application on my iPad. Weird thing is when I tap on the icon a black screen shows and nothing else happens.
I have done the following settings.
Main Interface - SSDMainViewController
Main Storyboard - Not set as I don't have any storyboard in the applicaion.
It is not the problem of IOS versions as other apps are working fine.
EDIT : When I double click the iPad button I saw that the application
is not crashing. It is running in the background.
EDIT 2 : More information on the question.
Well I have taken a view based application and it has all NIBs no storyboard. It was initially an iPhone application targeting the IOS 5.1 but then I have changed the value from the project drop down to UNIVERSAL. But that I think is no problem because when I installed it in my iPad it showed me nothing. Also it showed black screen with the iPhone frame and then nothing. The application is still live in the thread.
What bothers me is that I have done this in the AppDelegate :
I have set the
self.mainViewController = [[SSDMainViewController alloc] initwithnibname:#"SSDMainViewController" bundle:nil];
And then I have set the navigation controller and then pushed the view to it.
I FOUND SOME MORE INFORMATION
In the console it says.
The application is expected to have its root view set at the end of application start.
MY APP DELEGATE
ftipValue=0.25;
cardtype = #"American Express";
[cardtype retain];
[self CallFunctionForLogout];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Create an instance of YourViewController
//SSDMainViewController *yourViewController = [[SSDMainViewController alloc] init];
self.mainViewController = [[[SSDMainViewController alloc] initWithNibName:#"SSDMainViewController" bundle:nil] autorelease];
// Create an instance of a UINavigationController
// its stack contains only yourViewController
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:self.mainViewController];
navController.navigationBarHidden = YES;
// Place navigation controller's view in the window hierarchy
[[self window] setRootViewController:navController];
[self.window makeKeyAndVisible];
return YES;
Please use two xib file, universal app we want two xib (nib)
one for iPhone - ViewController_iPhone
second for for iPad - ViewController_iPad
Add following code to your AppDelegate.m file.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
}
else {
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I have done this and it's work fine for me.
That error means that you're not setting up your application correctly.
You say you've set SSDMainController as the main interface file - is this both for iPhone and iPad? There are two sets of entries in that section of the summary tab for universal apps.
I would expect a different xib file to be specified for the iPad, since a different sized view and different layout would be in use.
You have either not set the iPad xib, so the app can't set up a window with root view controller, or you haven't set up a valid iPad xib, so it isn't loading at all, with the same results.
If you just want the app to run in the mini-iPhone window with the 2x button, leave it as an iPhone only app.
If you are getting "The application is expected to have its root view set at the end of application start." there are a number of possibilities. Clearly, that is the problem, since you have a black screen with nothing in it...
Check out this SO question: Application windows are expected to have a root view controller at the end of application launch warning Rob Mayoff has a good description of what should be happening when your application initializes.
Also, linked to in the above post, is this post wherein there are an additional 35 answers with various scenarios of what could be happening.
Beyond browsing through those links, you will need to post up additional code and/or descriptions of how your nibs are wired up for anyone to help you--as evidenced by the myriad ways it is possible to cripple the initialization sequence.

iOS equivalent to Android Fragments/Layouts

In Android you can use Fragments to develop only one app targeted to phones and tables, so you can have different UI. You can even use only Layouts and have some condition on the code to run tablet or phone logic.
I need to develop an app for iPhone and iPad and I wonder if there is something similar for implementing different UIs and slighty different behavior. In my case the iPhone app would use tabs at the bottom of the screen, but the iPad one should use the menu on the left side.
Yes you can use Different UI for iPhone and iPad.
Create Two XIB files and when showing them on the screen use this condition to initiate the XIB
UIViewController *viewController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
} else {
viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil] autorelease];
}
[self.navigationController pushViewController:viewController animated:YES];
UIViewController and XIB, respectively.
Also see Creating a Universal App.

iOS Universal App - Access different Nibs for iPad and iPhone

I am writing my first universal app, I have converted my nibs so that there are iPad and iPhone versions.
The iPad version is in the Resources-iPad folder and called 'InfoViewController-iPad.xib'. The iPhone version in the main folder and called 'InfoViewController.xib'
I have the following action to show the relevant xib
-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
infoViewController = [[InfoViewController alloc] initWithNibName:#"Resources-iPad/InfoViewController-iPad" bundle:nil];
}
else
{
infoViewController = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
}
infoViewController.delegate = self;
infoViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:infoViewController animated:YES];
[infoViewController release];
}
When this runs on the iPhone it works fine, but it crashes when run on the iPad.
Any help would really be appreciared
You do not need to put the folder name in the nib name for the iPad version, it will be found as long as it has a different name than the iPhone version.
If removing the folder from the initWithNibName doesn't work for you, please edit your question and post the results of the backtrace from the console.
You should not need the Resources-iPad/ prefix on the name of the iPad nib. iOS knows how to find resources in your bundle. The folder hierarchy you see in Xcode is simply for organizing files and for the developer's benefit.