application crashing on ipod touch but not on iphone emulator - iphone

I followed the apple tutorial "Your First iOS Application" step by step and it works perfectly on the iPhone emulator.
But when I attempt to deploy it on an ipod touch, the application crashes.
here is the problematic method :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MyViewController *acontroller = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:[NSBundle mainBundle]];
[self setMyViewController:acontroller];
[[self window] setRootViewController:[self myViewController]]; // crash here
[self.window makeKeyAndVisible];
[acontroller release];
return YES;
}
And here is the error message :
011-04-13 18:07:53.730 ios_HelloWorld[865:207] *** -[UIWindow setRootViewController:]: unrecognized selector sent to instance 0x119520
2011-04-13 18:07:53.754 ios_HelloWorld[865:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIWindow setRootViewController:]: unrecognized selector sent to instance 0x119520'
2011-04-13 18:07:53.770 ios_HelloWorld[865:207] Stack: (
843631901,
849079828,
843635709,
843131673,
843094080,
11801,
857435720,
857434728,
857767424,
857765436,
857763988,
875472868,
843380011,
843377695,
857431048,
857424432,
11553,
11476
)
terminate called after throwing an instance of 'NSException'
Consider that I have followed the tutorial step by step (and re-did it by my own) and it always crashes at this spot.
Any idea?
thanks
KiTe

self.window.rootViewController vs window addSubview

Have a look at the documentation, the desired property is not available on that iOS Version. You will have to update or build in some conditional workaround.
rootViewController The root view
controller for the window.
#property(nonatomic,retain)
UIViewController *rootViewController
Discussion The root view controller
provides the content view of the
window. Assigning a view controller to
this property (either programmatically
or using Interface Builder) installs
the view controller’s view as the
content view of the window. If the
window has an existing view hierarchy,
the old views are removed before the
new ones are installed.
The default value of this property is
nil.
Availability Available in iOS 4.0 and
later.

The setRootViewController method is only available in iOS 4.0 and above.

Related

iOS - Testing view controllers

I've got a really weird and unexplainable problem and it's like the whole day I'm trying to fix it without any result.
I have setup a testing target for my iOS project, following the doc steps.
I'm using Xcode Version 4.5.2 (4G2008a).
I'm also using kiwi. Every test works fine, apart when it comes to load the view of a view controller with xib.
The view controller is a simple UIViewController with a MKMapView, a button and a searchbar, all properly hooked to the owner's IBOutlets.
In the test I'm writing something like:
__block MapViewController *mapVC = [[MapViewController alloc] initWithNibName:#"MapViewController"
bundle:[NSBundle bundleWithIdentifier:#"com.myorg.MyAppTest"]];
it(#"Loads the view", ^{
[mapVC loadView];
});
While executing the test (on iPhone Simulator 5.0) I get a bunch of these in the console:
ERROR: System image table has not been initialized. Do not ask for
images or set up UI before UIApplicationMain() has been called.
After that I almost always get this error
[__NSCFType pointSize]: unrecognized selector sent to instance
0x19cb970
On iPhone 6 Simulator I get initially this error
Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen
size
Followed by this
-[__NSCFType screenFontWithRenderingMode:]: unrecognized selector sent to instance 0xeba1540
I hope someone can help me, this thing is driving me mad.

iPhone: unable to start simple application

I'm trying to make an iPhone app here, and I've gotten it down to a simple HelloWorld problem. For some reason, the following does not work in XCode 4.4. I'd really appreciate figuring out what's going on.
I follow these steps:
Start an 'empty project' type
Name it
Add in a new objective-c class with a .xib. Say this new view controller is StartViewController, so I now have StartViewController .xib, .h, and .m.
Check: file's owner for the .xib matches the .h file. It does in IB.
Change the background of the .xib to something other than black (I like stripes).
Add these lines to the main app delegate:
import "StartViewController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
StartViewController* theController = [[StartViewController alloc]init];
[self.window addSubview:theController.view];
[self.window makeKeyAndVisible];
return YES;
}
And the app immediately crashes on running with:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "StartView" nib but the view outlet was not set.'
How can I make it work?
EDIT: PS, I have no idea why the code formatting appears to have failed. I was under the impression that it was just four spaces at the beginning of a line...
Do what am error tells you to do. Set an outlet for Startview in your VC.
I'm answering this because it's so ludicrous.
Turns out that order matters.
I deleted the old controlling files, and then added 'startingviewcontroller', edited the appdelegate function to be startingviewcontroller, then it all works. Not sure why that should matter, but hey.

performSelector throws UIViewControllerHierarchyInconsistency exception

I was developing my application on XCode 4.1, for iOs 4.3, but yesterday I've updated it to XCode 4.2 with iOs 5.0 SDK.
When I run my application in iphone 4.3 simulator, it works great.
I decided to test it on iphone 5.0 simulator, and following problems appeared:
I've got a view controller f.e "MyViewController", and a custom class which implements some custom component "MyCustomComponent" which is added to "MyViewController". There is a button in MyCustomComponent, and when its touched it peformSelector from MyViewController, and it leads to crash with EXC_BAD something. Same code works on iPhone 4.3 simulator just perfectly. Any ideas?
Custom navigation bar - doesn't work at all. I'm trying to set custom background implementing UINavigationBar, and overriding drawRect, but it doesn't shows in ios 5.
OK, so i guess I figrued it out. My console was off, when i reinstalled xcode, so didn't see any error messages. Turned it on now, and got an error
Terminating app due to uncaught exception
'UIViewControllerHierarchyInconsistency'
Problem was that I was adding MyCustomComponent to MyViewController using
self.view=myCustomComponent.view
when I should be doing
[self.view addSubview:myCustomCoponent.view]
it wasn't an issue in ios 4.3, but seems its a big deal in ios 5.
I struggled with the same problem.
When you create a new Master-Detail Application(without story board), you can see this codes below from AppDelegate.m.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
"BE NOT DEPENDENT ON MainWindow"
Just start from your own ViewController and set it to delegate.
And don't forget to unlink view from MainWindow.xib else the view will called 2 times.
EXC_BAD_ACCESS implies that the object doesn't exist. Try NSLog-ging the object on which you are performing the performSelector-method.
EDIT: If it crashes when you try logging it, it has been dealloced. Check if you retain the object correctly!
If it is a valid object, try:
if(![obj respondsToSelector:#selector(mySelector:)]){NSLog(#"no such method!");}

Crash (SIGABRT) while adding a view. (WebView)

I am having a crash (triggered by an exception) while adding a WebView. I haven't figured out why. And yes I have browsed the web because this is a very common problem though with no success, I found an answer saying that I should implement the DSYM to track the stack correctly, because looking at all those addresses is just meaningless (and I agree), the thing is I have no idea on how to do this. I found this: save dsym files. But I didn't figure out how to integrate it into my project, besides it looks dangerous. And yes I have NSZombie enabled too, but to no avail.
Anyway now to the point of my question. I have a button that triggers an event, the event changes a string (the URL) according to the button pressed. Then this IBAction calls on the delegate, and the delegate makes a transition to a view that has a UIWebView that will open with the URL edited by the IBAction. So I have the following code:
This is the Delegate method:
WebViewController *awebViewController = [[WebViewController alloc]
initWithNibName:#"WebView" bundle:nil];
[self setWebViewController:awebViewController];
[awebViewController release];
self.webViewController.finalURL = [NSMutableString stringWithFormat:#"%#", linkString];
[viewController.view removeFromSuperview];
// HERE happens the crash, found out using breakpoints
[self.window addSubview:[webViewController view]];
[UIView commitAnimations];
[viewController release];
viewController = nil;
This is the exact crash message:
-[WebView initWithCoder:]: unrecognized selector sent to instance 0x5718320
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '[WebView initWithCoder:]: unrecognized selector sent to instance 0x5718320'
I have the theory that it tries to make the transition but that there is no actual view to add. Though that is a wild guess. Exceptions are usually called by those kinds of things but in this case I don't see what is happening.
Thank you for your help, and forgive me if it is too dumb a question.
a guess from my side:
Do you have a view in your nib that should be a UIWebView but you changed the Class of that view to WebView?
You should first check this in interface builder.
This exception is exactly what happens if you change the Class of a view element to a class that isn't available.
The exact error is that some instance of a class called WebView (not UIWebView) at memory address 0x5718320 is being sent the message -initWithCoder:, which it doesn’t recognize. That message is called when loading views created with Interface Builder; check your nibs for a view that you’ve changed to a custom WebView class.
I had same problem, and renamed class WebView into WebViewCustom by XCode refractor/Rename feature, cleaned up project and now it works fine.

Does UIWindow randomly remove its subview?

The reason I ask is because I was doing the following in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
PageViewController *pageViewController = [[PageViewController alloc] init];
[window addSubview:pageViewController.view];
[pageViewController release];
[window makeKeyAndVisible];
return YES;
}
But, when I tried to scroll the pageView, whose controller implements the UIScrollViewDelegate protocol, I got an error like:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL scrollViewDidScroll:]: unrecognized selector sent to instance 0x5f42a80
When I took out [pageViewController release];, this error went away. This is weird to me because window should retain ... OH GOD!!! duh... it retains the pageViewController's view, not the pageViewController.
I get it now why it's wrong to release pageViewController. Silly me... I think it's time for a break.
It looks like you figured this part out, but the answer to your question is no, UIWindow does not randomly remove its subview AFAIK. In this case, it's retaining pageViewController.view not pageViewController. So, you shouldn't release pageViewController nor should you release pageViewController.view because pageViewController.view will automatically get released when pageViewController is released. I don't see where you are releasing pageViewController. I recommend making it an ivar of the AppDelegate and then releasing it in the AppDelegate's dealloc method, as you've probably done with window. The dealloc method never gets called, so pageViewController (and window) will never explicitly get released anyway, but making pageViewController an ivar is better style IMHO. Either way, I'll bet they get cleaned up when the application terminates.