integrating iOS4 project into iOS5 project - iphone

I have a newbie question about integrating two iOS apps. I have created an app in iOS 5 (my first app so I dont have any knowledge of iOS 4 except the fact thah there were xibs files instead of storyboard and also ARC was not included).
Now I have to include one older standalone app (built for iOS 4 with xibs and non ARC) to my iOS 5 app. Lets say that in my app on Main menu view there will be a new button opening the main menu of the other app.
So I did some research and find out how to disable ARC by the fno-objc-arc flag. Fine, now I have imported all the files of the second app to mine app and all the classes have the flag set.
I can still run my app without problem.
Now I have no idea how to let my new button to open the mainViewController of the old app - this app has MainWindow.xib (contains a window and one navigation controller). This MainWindow is set to be Main Interface in the old project. There are also some init call in appMainDelegate file. Where can I call them in my app?
Could anybody tell me what needs to be done. I have an idea, that I will add only one new UIViewController to my storyboard. This will be the starting point for the old app and than everything will work as it used to. Or will I have to create more controllers (for every xib) in my storyboard? This is where I dont know what to do. Any help much appriciated. thank you

Try doing something like the following, anything like it or simmular should work:
In the method of the button (the one you call your new button) have it execute the following code:
OldAppMainViewController *controller = [[OldAppMainViewController alloc] init];
//Here you can assign vallues to any properties that you might want to
[self.navigationController pushViewController:controller animated:YES];
That old apps main view controller should have a init with nub named function so it should work. If this does not work try something along the lines of:
OldAppMainViewController *controller = [[OldAppMainViewController alloc] initWithNibName:#"OldAppMainViewController" bundle:nil];
Where the NIB name is the .xib file name without the extension.
Also make sure that all connections in interface builder is setup correctly

Related

App update still points to old deleted nibs. How to resolve this without app re-install?

We have an app that is already live on app store.
Now we are planning to reduce the app size by programmatically creating all the views & removing respective NIB (XIB) files.
The problem is even when the nib is deleted & not called for, the updated version of the app still points to the old nib, and the issue like this comes up (this image is just an example, the problem is consistent throughout the app) :
Basically, the views get built up by both IB & code.
The only solution we have come up so far is to delete & re-install the app, but asking all the users to do that is undesirable. Moreover, it would also delete their locally stored app data, which is the main issue we are trying to avoid here.
For the above shown example, following code was used to load the ViewController:
Earlier (when the view was built using nib):
TheNewVC *theNewVC = [[TheNewVC alloc] initWithNibName:#"TheNewVC" bundle:nil];
[self presentModalViewController:theNewVC animated:YES];
Now (when the view is built programmatically, leading to above issue):
TheNewVC *theNewVC = [[TheNewVC alloc] initWithNibName:nil bundle:nil];
UINavigationController *addNavCon = [[UINavigationController alloc] initWithRootViewController:theNewVC];
[self presentModalViewController:addNavCon animated:YES];
JFYI, even if TheNewVC *theNewVC = [[TheNewVC alloc] initWithNibName:nil bundle:nil]; is replaced by TheNewVC *theNewVC = [[TheNewVC alloc] init];, the problem remains same.
What solution could be there that doesn't involve re-installation of the app. Any way we could delete the nib cache that iOS is referring to, programmatically? OR in worse case, ask users to do that? Any help would be much appreciated.
I assume you are running the app from within Xcode. Which does not clear out pre-existing resources from your app bundle. However when you install via the app store, I am sure it does clean your app bundle away and unzips the new version over the top (so old resources are cleared away..)
If you want to be double-sure your .xib won't be loaded, just rename the ViewController class and it will no longer load up the old xib (since it looks for a file called viewcontrollername.xib in the application bundle)
To do this go to the .h for the view controller, right click on the view controllers name, and select Refactor.

Root View Controller Error

I'm working along with the book Beginning iPhone 3 Development, and am running into some issues on the "Pickers" app. I'm using Xcode 4.2, and I set it up exactly like they have it set up in their source code. All the code is the same, and all the outlet connections are the same. But, when I run my version, it launches a black screen, and the debugger says "Applications are expected to have a root view controller at the end of application launch."
There version in the source code runs just fine, and mine looks identical to it, but for some reason mine just won't run. I've Googled this issue and people have a bunch of workarounds, but I feel like there is something really simple in IB that I'm not seeing.
Any help would be great, thanks.
The iPhone 3 book is probably having you add the view of your view controller as a subview of the window, correct? Well, since iOS 4, UIWindow now has a rootViewController property and setting this property to your initial view controller is now the preferred way to get your first view controller on screen.
Basically replace something like this in -application:didFinishLaunchingWithOptions: in your application delegate...
[self.window addSubview:viewController.view];
with this...
self.window.rootViewController = viewController;
Quite a bit has changed since iPhone OS 3; beware as you proceed through the book.
Do you have the RootViewControllers XIB-file? And is it connected to the RootViewController Class (in designer)

Linking One View To Another Via A Button

I'm a bit new to programming for iOS, and I'm having some trouble linking one view to another via a button. I'm just creating a simple little app that does some calculations on a NSDate in an attempt to learn XCode and iOS programming.
I've already searched this quite a bit, and I've tried to learn from other examples but I'm having trouble getting the view to present, nothing happens when I press my button (which I've already checked to be linked to the button).
I've been having trouble understanding view programming, so please bear with me.
Here's my code for my button:
-(IBAction)resultsPressed
{
TimeResults *timeResults;
timeResults = [[TimeResults alloc] initWithNibName:#"TimeResults" bundle:nil];
[self.navigationController pushViewController:timeResults animated:YES];
[timeResults release];
}
TimeResults.xib is using a Navigation Controller if it matters, while my root view is simply a view. My thinking behind this was so that I could get the "back" button (though I'm not sure if this is the correct way tot do this, since they are not a part of the same hierarchy). Any suggestions on how this should be done would be greatly appreciated!
Nothing seems wrong with the code you posted, but you should have the Navigation Controller associated with the first nib, as the back button will display by default when a new view is pushed onto the stack.
Also, make sure that the Navigation Controller is set up properly in your AppDelegate. The proper way to do this can be seen if you start a new project and select "Navigation-based Application". If you use the new project as a sample to show you how to set up your old project correctly, you will have to make sure that the nib is set up correctly too. I would suggest using the new project, hooking it up as a UIViewController instead of a UITableViewController, and then moving your code from your old project to this new one.
Finally, make sure that you always import the .h file of the UIViewController you are going to push to. Hope that helps!
To load another view, try
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
TimeResults *timeResults = [[TimeResults alloc] initWithNibName:#"TimeResults" bundle:nil];
[delegate.window setRootViewController:timeResults];
Hope it works. :)

Changes in Interface Builder are not showing in SImulator or Device

I have a view that I created using default buttons and background in Interface Builder. The app runs properly. I added .png background images to the view and to the buttons. Build the app and run it and the updates do not show.
I've also tried something simple like changing the text of the button or add another button and the changes are not propagating.
I've cleaned targets, manually deleted builds in Finder, and have shutdown the computer. What else am I missing?
I had the same experience. It turned out that I'd renamed my class and my xib file, but in another class I was creating the view with:
MyNewViewController *myNewViewController = [[MyNewViewController alloc]
initWithNibName:#"MyOLDViewController" bundle:nil];
An oversight, but the surprising part to me is that when this Nib file didn't exist in my project, it managed to build successfully using a (presumably cached?) old Nib file... and the application happily ran, though showing an out of date interface.
Correcting what was passed to initWithNibName immediately corrected the issue for me.
This might sounds easy - but are you sure you linked up the view to the view controller in Interface Builder? I've done it before where I just forget to link them
I also had the same experience. For me the fix was to reset all content on the simulator.

How to handle views?

How can I handle different views in XCode?
Let's say I want to show a different view when the user press a button.
UIViewController *viewSettings;
[viewSettings initWithNibName:(NSString *)#"SettingsViewController" bundle:(NSBundle *)nil];
This code don't work. The app crashes.
I have updated my XCode to the new version. How can I say my projects that they have to take the new SDK?
Thanks.
This is the correct line. Then you need to push it (pushViewController) onto a UINavigationController or add it to an existing view. Do a Google search for iPhone Beginner Tutorial First Application or something like that.
UIViewController *viewSettings = [SettingsViewController initWithNibName:#"SettingsViewController" bundle:nil];
1) You use a UIViewController to manage the view stack and ultimately which view is visible.
2) In your xCode project, modify the project or target "Base SDK" property. This will let you choose the minimum version of iOS to require of your users.
You need to read the Apple documentation for view controllers There are also some very good beginner books out there for iPhone programming