How to avoid old xib cache on released iphone apps? - iphone

I'm developing my first iPhone app.
One day, I renamed some files including xib file and its view controller.
After that, my app began to use old xib file.
I deleted xib file, but the old xib still was used.
The code to init view controller was:
MyViewController *vc = [[MyViewController alloc] init];
I modified the code to:
MyViewController *vc = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
Then my app used the new xib instead of the old xib.
The question is, is it possible that old xib files are displayed not only on developing apps but also on released apps for some reasons?
Can I avoid old nix caching on released apps if I use initWithNibName: instead of init?

I think you need to remove the files in DerivedData. I've been through this sort of thing. If you're using the Simulator, I'd also reset the simulator or delete its files.
Paths:
/Users/yourname/Library/Developer/Xcode/DerivedData
/Users/yourname/Library/Application Support/iPhone Simulator
You could get fussy, but I usually delete the DerivedData directory when I am having trouble. Xcode will rebuild them in less time that it takes to worry about the problem. In the iPhoneSimulator, you can find your app fairly easily and delete that directory if you choose.

In Product->Clean and then after Execute this will be solve your problem.

Related

Upgrade iPhone-Only app to Universal doesn't create -ipad classes

I'd like to upgrade my iPhone-only app to Universal. So, from the targets' general window I switch from iPhone to Universal and select "copy" for generate iPad Storyboard based on the iphone one. Now a new folder named iPad is created but is empty and I can't find all of the -ipad classes. What I want is to have all of the original (iPhone) classes duplicated with the -ipad suffix and a iPad dedicated Storyboad. Starting from these classes, and from the iPhone logic I want create step by step a new ipad version. In the targets' general windows ipad main interface is main_iphone-ipad but in the project doesn't exist, in the folder neither.
This isn't an issue with Xcode, thats what its supposed to do.
You can certainly duplicate your entire project for the iPad version manually if you'd like, but I can't think of a case where you'd actually want to do this.
Most of the time you just want to change the View layer between the iPad and iPhone version. You can load a different Nib based on the device you'd like or even load completely different view controllers doing simple logic like
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
viewController = [[MyViewController alloc] initWithNibName:#"ipadNIB" bundle:nil];
} else {
viewController = [[MyViewController alloc] initWithNibName:#"iphoneNIB" bundle:nil];
}
** BEGIN EDIT **
To setup a different storyboard for iPhone/iPad all you need to do is create another storyboard and name it "myprojectname_ipad.storyboard" then in the Info.plist for your project add a key called "Main storyboard file base name (iPad)" with a value "myprojectname_ipad"
** END EDIT **

initWithNibName not working

Just ran into this very frustrating problem when trying to add a new view, I have 2 different types of view: LargeCoverViewController and CoverViewController.
I created a LargeCoverViewController like this:
LargeCoverViewController *tmpCover = [[LargeCoverViewController alloc] initWithNibName:#"LargeCoverViewController" bundle:nil andIssue:issue];
That just works, but when I try to create a CoverViewController, it refuses to work
CoverViewController *tmpCover = [[CoverViewController alloc] initWithNibName:#"CoverViewController" bundle:nil andIssue:issue];
I'm thinking it has something to do with the .xib file, when I do like this it "works" again
CoverViewController *tmpCover = [[CoverViewController alloc] initWithNibName:#"LargeCoverViewController" bundle:nil andIssue:issue];
In Interface Builder the class is set properly, my view is linked up correctly. (It's basically just a copy of the LargeCoverViewController), am I still missing something?
It's getting very frustrating ...
EDIT:
My application doesn't crash, if my nibname was wrong the application should crash, which isn't the case here.
Try creating new separate XIB file rather copying whole XIB file and then copy the UI outlets and views from other XIB to this newly created XIB file.
Sometimes, Xcode gets confused with copy-pasting. I know this is not proper solution but sometimes it works. :)
When copying ViewController, the fileowner's custom class remains the same so change it to your new ViewController and once again bind your view after changing.
Is your application getting crashed on that line? Check the console for the logs. You may have got error messages or crash logs.
If you copied XIB resources from any other XIB then check for the linked outlets with objects which may not be available to this new class.
I hope this will help you and will able to resolve the issue.

integrating iOS4 project into iOS5 project

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

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.

Could not load NIB in bundle - inspiration needed

I'm currently seeing this error:
MonoTouchException: Objective-C exception thrown. Name:
NSInternalInconsistencyException Reason: Could not load NIB in bundle:
'NSBundle </Users/imac/Library/Application Support/iPhone
Simulator/5.0/Applications/5D8B4B51-9FB2-4331-BFEB-B1A0AC77DF42/Tutorial.app>
(loaded)' with name 'MyFirstView'
I've looked through lots of other questions like:
NSInternalInconsistencyException Could not load nib in bundle
Could not load NIB in bundle
and lots of others
But I can't see that any apply here - they are mainly about file naming issues and my Nib does appear to be in the output package file with the correct name.
I'm using MonoTouch 5.2.5 and xcode 4.2, and targeting SDK5
Does anyone have any ideas about what I could try to fix this?
I have faced the same Problem today. I refactored (rename) viewController to myCustomViewController and got this error. When I searched in my project files, I saw that I have used self.viewController = [[[MyTableViewController alloc] initWithNibName:#"viewController" bundle:nil] autorelease];
NibName was changed but in #" " it was old name. so I changed it to
self.viewController = [[[MyTableViewController alloc] initWithNibName:#"MyTableViewController" bundle:nil] autorelease];
and error was removed. Do it and hope your error will be removed.
Vote up if it helps.
The problem eventually it seems was somewhere in the extended toolchain - somewhere between MonoDevelop, xCode4 and the simulator.
Restarting everything, and resetting the simulator cleared the problem.
Later in the same chain I've seen smaller issues with "old NIB file outlets" persisting on the simulator even after I've definitely deleted them and rebuilt - so something is still going wrong somewhere... but a clean solves it each time.
So I had a similar solution in MonoDevelop. I created an empty mono touch project. When I deleted the xib file associated with the auto created project, i ran into problems. Even though I created a new view and connected the outlet to that controller, I had to go back and recreate the xib file associated with the controller (with the same name) again, and then connect that original view and controller via the outlet