UIImageView from Storyboard nil on simulator - iphone

I have a quite normally wired UIImageView in a viewController in a StoryBoard. When I run the app on the iPhone it is correctly assigned in the code, while if if I run in the simulator it remains nil thus crashing the constraint trying to locate it. That would not be a big deal, were it not for the need of producing the screenshots for the iPhone 5 I do not own.
All other objects are correctly loaded also on the simulator.
The name is "appending" that I do not think is a reserved word, and I tried also to load a different image in the control with not variation.
What could it be?

Related

setStatusBarOrientation causing problems in iOS8

I'm having real problems with my apps under iOS8. I've made a bunch of OpenGL based apps, which don't need the iOS to handle the orientation. It's all handled within the OpenGL section. But I do use setStatusBarOrientation to make sure any dialogs/keyboards etc that pop up line up with everything else. I'm creating my window and view programatically or in a xib, I've never needed to use a storyboard (in case thats relevant?)
It's all been perfect, til iOS 8 came along.
Now it seems that setStatusBarOrientation isn't behaving properly at all. It's either not changing anything, or it's rotating "something" that stops touches being recorded on half the screen. It's as if the window is being rotated within itself, but visually nothing changes, just the touches are effected.
It's hard to explain, and makes no sense.
But my question is: How do you set the status bar orientation in iOS8? And how do you do it without destroying everything else that works in previous iOS versions?
Set iOS7.1 as your Base SDK, and it'll work fine on iOS8, without all these strange bugs.
http://objcsharp.wordpress.com/2014/09/21/how-to-get-back-the-ios-7-sdk-after-upgrading-to-xcode-6/
found this
if ([UIViewController class]) // iOS8 has this class only
{
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:#"orientation"];
}
found here:
http://blog.lessfun.com/blog/2014/09/24/ios8-issue-keyboard-orientation-and-idletimerdisabled-not-working/
seems to work

Gestures handled identically in iPhone and iPad

I'm working on an app right now where a tap will be handled identically on the iPhone as on the iPad. I don't have an iPhone, so I'm using the simulator to test for now. I thought I could simply click with my mouse on the screen if the simulator to simulate taps, but that doesn't seem to work.
So I had the thought that maybe the problem was that I started with iPad and created the iPhone interface later (although the project itself was generic from the start).
I copied the gesture recognizers (tap and two swipes) from the storyboard for the iPad and pasted them into the storyboard for the iPhone. I didn't think this was going to work, but I was hopeful that's all I would have to do. In any case, it seems like the same code should be able to be linked from both storyborad gesture recognizers.
When that didn't work, I hooked up the iPhone gesture recognizers using Control-drag just like I did with the iPad. This created new methods. Since the same code could be used, I thought I'd simply call the other:
- (IBAction)tapIphone:(UITapGestureRecognizer *)sender {
[self tapIpad:sender];
}
- (IBAction)tapIpad:(UITapGestureRecognizer *)sender {
omitted code
}
That didn't work either. So next I tried copy/pasting the code from the iPad method to the iPhone method. It still didn't work.
So now I'm wondering if maybe I don't know how to test taps properly on the iPhone simulator. What else could I have missed?
It seems clear that the tapIphone method is not being called at all. You can work that out by adding #NSLog("tapIphone") in the method, see if it logs. In fact put these lines into their respective methods:
#NSLog("tapIphone");
#NSLog("tapIpad");
If tapIphone WAS getting called and the tapIpad method IS in the same class, the expected behaviour should have occurred.
Your first intuition, to copy and paste items from one storyboard to the other, is fine. However you lose all IBAction / IBOutlet connections when you do this (they don't carry over their links to and from the old storyboard, they just go), so you have to rewire them each time. Which is a bit of a pain when you are trying to adapt interface from one device for another. This does not mean that you have to create new code - it just means you have to CRTL-drag from each storyboard item onto the existing IBAction code item you want to reconnect to (you can achieve the same result by CTRL-dragging from the storyboard item to the relevant controlView storyboard icon, which will present you with a list of optional IBAction items to connect to). Same goes for any IBOutlet connections you want to replicate.
This is not an issue with the simulator, you just need to tweak your understanding of storyboard wiring.
I would not recommend your suggestion of separate IBAction methods as a way to handle different behaviours on different devices. This will lead to more wiring complexity which is irritating to debug. There are better ways to do that, for example by checking environment capabilities or using:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//iPhone code goes here
} else {
//ipad code goes here
}

Xcode application running on Iphone but crashing on Ipad

I made a universal application that contains NIB files for both ipad and iphone UI's. In my view controllers initWithNibName method I call UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM() to detect whether the controller is running on iphone or ipad.
I then launch their respective nib files. When I run the app on iphone, it works fine, but when I run it on ipad it eventually crashes with a EXC_BAD_ACCESS error. This error occurs when I use a view controller to launch another view controller, which then launches another one in the navigation stack. This error occurs as soon as I click the view that belongs to the third controller of the stack.
I cannot distinguish a difference between the NIB files that would cause a crash. I have been working tirelessly to figure out why this is happening but I cannot fix this error. Does anyone have any insight into what might be going on?
Any advice on how to approach fixing this problem would be very appreciated.
The first thing you should do is enable the "All Exceptions" break point. This will often accurately tell you the line of code where the EXC_BAD_ACCESS is happening.
Next, I would turn on zombies and see where the over-release is happening. To do so, in Xcode, while holding the option key, click Product | Run.... In the ensuing window, add NSZombieEnabled to the environment variables list.
Then run. Do the normal things you do to cause the crash and see where the debugger lands. With any luck, it will stop where the problem is actually occurring.
When you get a EXC_BAD_ACCESS it means you're trying to access/release something that's already been released. If you're in a non-ARC situation, it normally means you've inadvertently released something when you didn't mean to, so just check for alloc/init and release balance. If, however, you're in an ARC situation, I would bet it has to do with not niling a delegate when a view controller gets released.
For example, if you have a MKMapView and have set its delegate to your view controller, you should nil its delegate when your view gets unloaded or dealloc'd. Otherwise, messages will continue to get set to it. Or, another possibility is that you've added your view controller as an NSNotificationCenter observer and didn't remove it as an observer when the view controller was unloaded or dealloc'd.
Another possibility is that you're re-using view controllers between the two versions of your universal app. If you are accessing anything by an identifier that doesn't exist in the nib for the iPad, that would cause a crash--though if you're using nibs as opposed to storyboards, that may not be an issue.
That's about all I can think of for now. Try to zero in on where it's happening and post code here if you still can't figure it out.
Best regards.

Updating iPhone app to Universal: IBOutlets

First off, I will say i've spent 6 hours on this topic and have read everything the internet has to provide, which is why i came here.
I have converted to Universal, Xcode created the MainWindow-iPad.xib and everything seems fine.
Here are my questions:
1) What are the naming conventions for new iPad-specific xibs? Xcode created "-iPad" but i believe im supposed to be making them "~ipad". Why the difference?
2) (MOST IMPORTANT) After creating several "~ipad" xibs, Xcode seems to know to load these. So I'll copy the content in say, "RootViewController.xib"
and paste it in "RootViewController~ipad.xib". THIS IS THE PROBLEM: this new ~ipad xib has no outlets or referencing outlets!
I can't link the buttons on my page to anything. How do i do this without having a separate ~ipad .m and .h for everything?
Thank you guys for your help! I'm going to write a tutorial on this once I get this all working.
Just set the class of that ~iPad nib to be the same classname as the cooresponding iPhone nib. This is done in the inspector in Interface Builder. You may have to connect the outlets back up depending on the order you do things. I would think that if you copy the objects from the iPhone nib to the iPad nib AFTER you set the class, then the outlets would stay wired up.

SIGABRT on iPhone when changing xib

I've just finished off an app for the iPhone which, until today, ran fine on the iPhone simulator and actual devices.
I tried changing the xib which is loaded in the applicationDidFinishLaunching method in my application delegate class - all I did was change the string in initWithNibName.
When I launch the app on the simulator, the Default.png image is shown, then the app crashes with an uncaught exception. When running on a device, the Default.png image is shown for about 10 seconds, the UI is never loaded and I get 'GDB: Program received signal: "SIGABRT".' on the Xcode status bar. Debugging shows that applicationDidFinishLaunching is never actually reached before the app crashes.
Setting the starting xib back to the original solves the issue, but now I've made a change and saved it in the Interface Builder and the app shows the same issues as above - I've made no code changes at all.
Is this a memory issue, or a known issue of a common mistake?
NOTE: I've made no code changes whatsoever, and the only changes I've made to the xib are cosmetic, the IBOutlets are all intact.
You probably changed an IBOutlet's name in code without changing it in the xib.
Sorry guys, my fault - it appears I deleted the MainWindow.xib file, so the delegate wasn't called on startup after I made changes. I've recreated it and linked it to the app delegate and UIApplication so now everything works.
You probably had IBOutlets connected from a xib back into your code, and those connections are broken.
You'll have to give us a little more detail on how the nibname string was changed. Did you rename your xib file?
I renamed some classes and Xibs and got SIGABRT into main.m
the Class name in Identity Inspector may be pointing to non existant class name
its because in the initWithNibName you are not giving the correct xib name so it will crash