Xcode 4: nib files not loading when run - iphone

So, I just downloaded Xcode 4 and installed it. I was actually quite looking forward to the single window and integrated IB...
-
However, when I open and run one of my projects, the nib files that the project uses don't seem to load. Instead I'm left looking at a blank white screen (iPhone). This project ran well and fine on Xcode 3.2.
If I background and un-background the app, the view loads fine. But this happens every time I build, on both iPhone and iOS simulator, i.e. the app doesn't work properly until it's been backgrounded. All the code for loading the view follows from
- (void)applicationDidFinishLaunching:(UIApplication *)application.
-
Did anyone else have the same nib file problems - is there a fix (or something stupidly simple that I'm forgetting about)?

Ok after a lot of messing around, I figured out the nib problem.
I had a stray line of code in the appDelegate class:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
This line of code doesn't affect anything when compiling with Xcode 3.2, but with Xcode 4 causes the loading problem. Just remove it (I don't even remember why it was there...) and it's fixed :)

I'm not sure what's going on with your nibs, but this XCode 4 transition guide should be of some help for finding missing panels, menus etc...

I had the same problem. In my case, for some reason Xcode had decided to hide the view in question. It cleared up when I put the following into the viewDidAppear method of the view controller:
self.view.hidden = NO;

For anyone with the same error. If upper won't help - check if you did not overwrite the view attribute of your ViewController.

Related

View doesnt navigate in real ipad device but works fine in emulator

In a button click I am navigating the view to another xib which works fine in real iphone device, ipad iphone both emulators but not in real ipad. Here is my code :
-(IBAction)cardAnimation{
ViewController_ipad *view = [[ViewController_ipad alloc]initWithNibName:#"ViewController_ipad" bundle:nil];
[self.navigationController pushViewController:view animated:YES];
}
but one thing to be noticed that I have done NSLog in my destination class's viewdidload method and surprisingly that thing is being logged though that view is not being loaded at all by the above code. What can be the problem?
I think you have a MainWindow~ipad.xib file that is referenced through your AppDelegate and you also tried to alloc the Window in your didFinishLaunchingWithOptions: method in your AppDelegate file. For which there might be some problem occurred. Whenever you are trying to push your navigation controller, it is actually pushing, but not showing the next controller may be because of the Window over that controller.
It might solve your problem:
Go to your Project settings (not through File->Project Settings) by clicking on your Project at the left panel/navigator -> select your TARGET and go to Summary Tab -> scroll down to iPad deployment Info -> there you'll find the Main Interface option -> remove the name "MainWindow_iPad" and left it empty and save it. Run the application in your iPad and it will work fine.
Best of luck. :-)
N.B: Don't forget to clean your build and remove the application from your device before you go for the new build.
The iPhone simulator is case-insensitive for file names. The devices are case- sensitive. Check to make sure that your nib name isn't actually Viewcontroller_ipad or ViewController_iPad or another variation. This behavior once got me trying to use an image file in my app - it would work in the Simulator, not on device.
Try a fresh install (deleting the app), and if you are building from xcode hold Option and go to Product - > Clean Build Folder
Also are you naming your nibs with ~iphone and ~ipad?
I faced the same problem, i had problem with my iPad (iOS 5.1.1).
When i was pressing button but that was not responding.
That is because of i added UIGestureRecognizer on self.view.
I solved this problem by adding gestureRecognizer on my button. (its just trick not an proper solution, Just implement it if you did not find any other way.)

Changes made to UI objects are not updating in iPhone simulator

I'm new to objective-c and iPhone, but have done lots of java coding in past.
Tearing hair out about v. basic things which I'm usually eventually able to find answer to, but not this one!
I'm wanting to make a label's background colour change, code below. No matter what I do it doesn't change when I run it on the iPhone simulator. Is there some setting there, I feel like I'm asking a very stupid question but really can't find an answer. Is this a problem with the setup of the development environment??
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(#"setting label to black color");
self.colourLabel.backgroundColor = [UIColor blackColor];
}
Why don't you make an IBOutlet of type UILabel, hook it up to the label in the interface builder and do:
yourLabel.backgroundColor = [UIColor whateverColor];
Did you set colorLabel as a property? Because you wouldn't need to... unless you have two separate classes that you want to communicate with each other.
Remember that in Objective-C sending messages to nil objects is fine, so the problem may be that self.coulourLabel is still nil at that time.
How and where do you instantiate it? Did you set the IBOutlet?
Just thought I'd leave an answer emphasising the suggestion from #Dima in the comments on the question - ie, Project > Clean and then iOS Simulator > Reset Content And Settings.
I just solved a similar problem which was occurring with a UIButton created in code, and so couldn't have been an IBOutlet issue. Changes I made to the code (even deleting the property altogether) weren't showing up when I ran in the simulator, even though on my device it worked fine. I had assumed that doing a clean would be enough but it wasn't until I did the Reset Content And Settings that it started behaving as I expected.
Hope someone finds this useful...

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)

Xcode 4 - viewDidLoad issue

Is anyone else having issues with Xcode 4 where viewDidLoad is being called twice? I have run the same project in both Xcode 3.2 and Xcode 4 and it only acts up in Xcode 4.
After researching this on the Apple Developer forums, it seems that in some cases Xcode 4 creates bugged Interface Builder NIBs. The effect is that the application's rootViewController gets loaded in twice, which really screws things up. The same project loaded in Xcode 3 won't exhibit the problem.
In my universal app, it only affected the iPad NIB. The iPhone was fine.
I was able to solve this issue by:
Removing the rootViewController connection in Interface Builder (this causes the app to load with window.rootViewController = nil)
In viewDidLoad for the main controller (the one that was being loaded twice), I then manually assign appDelegate.window.rootViewController = self
So far this seems to have the desired effect.
Xcode is just the IDE -- it shouldn't have any bearing on what happens when your app is executing. If there's a difference, it seems more likely that you're building for different iOS versions.
Did you set the view of the view controller? I had the same issue and I realized that I didn't set the view property.
- (void)viewDidLoad {
UIView *contentView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame];
//add some stuff to contentView here
self.view = contentView;
[contentView release];
}
I had same issue. And i resolved it. It happens when your app memory did get memory warning.
Put a breakpoint to memoryDidReceiveWarning. It get's called, and clear your class object memory. So your viewDidLoad Get called twice, because it has no memory at that time.

Strange behavior with MainWindow.xib, app will not reach didFinishLaunchingWithOptions

I've started a new project in Xcode 3.2.5 where everything is being done in code. I don't want to use xibs this time though am looking forward to an integrated IB in Xcode 4.
The problem came up when I edited a string in a json file. On running the code I noticed the old string appearing even though the file was certainly changed, so I deleted my Library/Application Support/iPhone Simulator folder, expecting that my json changes would then be loaded to the bundle and the code would then see the expected value.
Then command-Y to build and run and it wouldn't run. Although there is no MainWindow.xib in my project folder my Info.plist file refers to MainWindow.xib. (I removed it, following the creation of this iPhone app with Xcode's New Project template) So I removed that key from the plist figuring the xib must have been sitting around in the app bundle after being installed in the simulator the first time I ran the app.
Then I ran the app again. No complaints, only a black screen - and a breakpoint in my app delegate, on didFinishLaunchingWithOptions is not being hit.
I have not changed anything in main.m. How can it be that the app is not launching?
I think something got messed up when you removed MainWindow.xib. Try these steps to see if it'll correct the problem.
Under the Project menu, choose Edit Active Target. Select the Properties tab and blank out the Main Nib File field. Close the Target Info window.
Under the Other Sources group and edit the main.m file. In the UIApplicationMain function call, change the last parameter to the name of your application delegate class.
int retVal = UIApplicationMain(argc, argv, nil, #"AppDelegate");
In your application delegate you need to create a window object. I do this in -applicationDidFinishLaunching:. If you defined anything else in your MainWindow.xib, you can probably create that here, too.
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UIWindow *appWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = appWindow;
[appWindow release];
}
If this doesn't work, let me know and I can give you another way.
Sounds like you dont have a view connected in the XIB.
This is the same as #"AppDelegate" but you can write like this too :
(argc, argv, nil, NSStringFromClass([AppDelegate class]))