Xcode / Simulator iPhone messes up display - iphone

As you can see, the simulator misses text on some buttons. I also saw this same behavior following along on the TapCounter demo off of YouTube.
Another issue (not shown in the screenshot) is that if you press on any key on TapCounter, NSString stringWithFormat (see below)
- (IBAction)add {
count++;
number.text = [NSString stringWithFormat:#"%i", count];
}
The act of executing the stringWithFormat line nukes the formatting on the label and reverts it to default value.
I did make sure that the simulator size and development size are identical, as you canm see.

This question appears a few times on this site. The answer at this related question worked for me, once I was able to interpret the instructions. Including getting the crash and fixing it.
Later: it appears that the fix of turning off auto-layout is enough to get the 6.0 simulator working - you might like to try this first to see if all the other stuff is actually necessary...

Related

all UISteppers in my iOS app have become disabled

My app uses UIStepper controls in a few different views. I released a minor update to the app that shouldn't affect these views at all, and I started getting reports that all the UISteppers in the app are now disabled. One user sent a screen shot, and the stepper control appears as if its enabled property were set to NO. However, there's no place in my code where I set this property at all, and the default is YES. I've searched my app for instances of the term "enabled" to make sure I'm not somehow disabling it accidentally, and I'm not.
I thought perhaps the default value for the enabled property changed between iOS versions, but the users who have reported this are running iOS 5.1.1, the same as my development devices. And I only started hearing about the problem with this app update.
Besides setting the enabled property, I found that the steppers will be disabled if the min and max values are set to the same value. I'm pretty sure this is not happening in my app. The values are hard-coded and passed to a setup method, and I haven't changed this code since many app versions ago.
Do you know any other reason why this would happen? I can't reproduce the problem myself, and it only affects some users, so it's difficult to troubleshoot.
Here's my code for creating the UISteppers, for what it's worth:
- (UIStepper *)makeStepperInput:(float )currentValue minValue:(float)minValue maxValue:(float)maxValue increment:(float)increment {
int stepperWidth = 94;
int stepperHeight = 27;
CGRect stepperFrame = CGRectMake(0, 0, stepperWidth, stepperHeight);
UIStepper *stepperInput = [[[UIStepper alloc] initWithFrame:stepperFrame] autorelease];
stepperInput.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[stepperInput setValue:currentValue];
[stepperInput setMinimumValue:minValue];
[stepperInput setMaximumValue:maxValue];
[stepperInput setStepValue:stepValue];
[stepperInput setContinuous:NO];
NSLog(#"making stepper with values %f, %f, %f, %f (%i)", currentValue, minValue, maxValue, stepValue, stepperInput.enabled);
[stepperInput addTarget:self action:#selector(onChange:) forControlEvents:UIControlEventValueChanged];
return stepperInput;
}
UPDATE: I have a user who was willing to install a debug version with the NSLog line above. He sent me the console output and it shows that the min and max value of the stepper are correct (1 and 20 in one case) and that the enabled property is YES. Unfortunately, that eliminates both of my theories about what could be happening here...
Okay, here's what happened. The method posted above is a simplified version of my real method, which provides some branching for pre-iOS 5 devices. To help with pre-iOS 5 support, I was actually declaring stepperInput as a UIControl, and then returning something different on iOS versions that don't support UIStepper.
Now the interesting part. I rolled my project back and started looking at my build settings, and remembered that before my last release, Xcode gave me one of those alert messages about my build settings being out of date. I had clicked the button to allow Xcode to make all the recommended changes. This time, I performed one change at a time and tested my app after each change.
The first of the recommended changes was to "Upgrade Compiler configuration to LVVM". ("The compiler configuration is set to 'com.apple.compilers.llvmgcc42'. This will upgrade to 'Apple LLVM compiler 4.0', which is the recommended setting for iOS targets.") As soon as I made that change, the problem appeared on my test device. So it seems that the old compiler allowed me to set UIStepper properties on an object declared as a UIControl, while the new compiler did not. Indeed, when I changed my NSLog line above to output the actual values of the stepper, instead of the values passed into the method, they all returned 0. Having its min and max values both set to 0 is what made the stepper appear to be disabled.
I didn't think this affected all users because I couldn't reproduce it, but I was testing with the older build settings rather than the build settings used for the release. So now I'm thinking that this probably does affect all users, and only some users have noticed it.
Anyway, the solution is to reorganize my code so I can declare that UIStepper as a real UIStepper, since the newer compiler doesn't allow the kind of fudging I was doing before.

Images in iPhone app appear in Simulator, but not when compiled to device

I am learning iPhone development, and have built a simple app that has an image that changes to another image when you tap it.
If i build it to the simulator, it works fine, but if i build it to the device the images dont appear. i feel like they aren't being copied across. I have checked they have been named correctly and i have made sure i imported them to 'resources'
I dont think it is a problem with the code because i added a thing to also make text appear when the image is tapped, and this works, so a button is still there doing something, it just doesn't have an image on it.
-(IBAction)changeImage:(id)sender {
[fortuneCookieButton setImage:[UIImage imageNamed:#"Image2.jpg"] forState:UIControlStateNormal];
label.hidden = NO;
}
-(IBAction)restoreImage:(id)sender {
[fortuneCookieButton setImage:[UIImage imageNamed:#"Image1.jpg"] forState:UIControlStateNormal];
label.hidden = YES;
}
Does the case (upper/lower) of all your file names match exactly for all letters? Source code & project & Mac?
just to share with you, I had this same problem and I found out the solution: I was using lower case in the file name and upper case in code. The thing is on Simulator there was no problem because Mac file system is case-insensitive but in the iPad it didn't work because iOS file system is case sensitive. ;-)
I had this problem. Bizarrely the image had been working in the past, then just stopped appearing on the device one day.
It was a PNG.
I opened it in GIMP and saved it again. Then it went back to working again. No idea why.
Crazy.
Is it the case with only PNG images or also for JPG & other format you're having same issue. If it's only for PNG image, then it might be possible they're not being compressed. Try the following way.
Select your project target & go into its info. Here go into the build tab. In the configuration select "All Configurations" from Configuration section. Now, write "COMPRESS_PNG_FILES' in the search bar. And see the status of the check-box. IF it's unchecked, then make it checked & it will work. But if it's already checked, then there should be other reason in your project.
In the later case, I would request you to create a new dummy project & check by adding 2-3 images whether it's coming or not.
Clear caches delete the previous build and try again.
I also had same problem, and it was caused by a different reason: my project has image files with the same name! Since my app has many images, I inadvertently included images with the same name. Simulator is more tolerant and show the images just fine; however, when built on device, neither of the images of the same name were copied to the build directory. Obviously xcode is more picky for device: since all images go to the same directory, the file names must be different. When there are files with the same name, xcode refuses to copy any of them since it doesn't know which one to pick.
I have the same problem. In my case, the issues is to do with the UILabel above the UIImageView that shows the image. When I change the type of UILabel to AttributedText (In Property Inspector), my real devices cannot load the image. When I change it back to Plain, it works now. I use XCode 6.2.
on top of all suggestions - it wasn't work for me until I restarted the device

How do you disable phone number detection in mobile safari

I have tried to disable phone number detection in safari for my web app but it still shows 7 character strings comprised of numbers as phone numbers. I used the apple provided meta tag but no joy.
<meta name="format-detection" content="telephone=no">
Anyone else run into this problem and work around it?
Thanks.
Update: It looks like it does not detect phone numbers in safari but rather when I save the page as an icon and run it from the home screen.
Are you loading this in a UIWebView? If so, you need to set the property for dataDetectorTypes. e.g:
webView.dataDetectorTypes = UIDataDetectorTypeNone
Valid detector types are here.
Search for UIWebView on apple's site for a description of how to set the property there.
-Kevin
We had a similar problem on our JQM/Cordova app. We had a calculator built into the app and whenever the amount was more than seven digits the data would be in blue with an underline underneath and when you click on the data a pop up appeared and gave you the option to call. We simply added
the meta tag as described in the opening question & it worked.
Just adding some thought here in case anybody else has a similar issue with Safari detecting 7 stringed data as telephone numbers.
OK. After quite a bit of futzing I think I found a strange work around. The problem with using dataDetectorTypes is that it will disable phone number detection for the whole uiwebveiw.
After trying datadetectors="off" and x-apple-data-detectors="false" attribute on span and a tags I finally stumbled on something that seems to prevent phone number detection.
If I wrap my text in an a tag with an href="#" apple seems to leave it alone.
Try this Code,
webView.dataDetectorTypes = UIDataDetectorTypeNone;
This may help you.
Try and add this to YourProjectAppDelegate.m
// ...
- (void)webViewDidStartLoad:(UIWebView *)theWebView
{
theWebView.dataDetectorTypes = UIDataDetectorTypeAll ^ UIDataDetectorTypePhoneNumber;
return [ super webViewDidStartLoad:theWebView ];
}
// ...
Did the trick for me..

Why does XCode show the wrong object address in the debugger window?

My application tested whether my selectedViewController was equal to my moreNavigationController.
if( self.tabBarController.moreNavigationController == self.tabBarController.selectedViewController )
{
// do something awesome.
}
else
{
NSLog(#"No match");
}
The expression always evaluated false, so I started debugging. I put a breakpoint in the code and hovered my pointer over 'self', which caused the yellow cascading popup where I could see the addresses of both Controllers. The addresses were the same in the popup, which must be incorrect since the if statement failed. I see the same result in the debugger window.
I added these logging statements later, which revealed that the objects had 2 different addresses.
NSLog([NSString stringWithFormat:#"%d",(self.tabBarController.moreNavigationController)] );
NSLog([NSString stringWithFormat:#"%d",(self.tabBarController.selectedViewController)] );
Why did the debugger window lie? Specifically, does anyone know what value it displays as its address, and why the controllers would show the same address?
I have had this exact same problem, and I'm 90% sure it's related to building for a 2.1 (or possibly 2.X) SDK while using the 3.0 dev tools. In my case, setting the target SDK for 3.0 fixed this issue.
Having your debugger essentially lie to you is frustrating ;)
I am seeing EXACTLY the same thing. Especially with floats. I switch to 3.1 target and it displays right. The question is, is the code really working correctly under 2.1 (an NSLog of the variables tells me it is).

What's the best way to log debug info in an iphone app?

Is there some standard way or has anyone written something that allows you to log a message and have it be displayed either in a small scrolling section on the iphone screen or in a separate window in the iphone simulator?
Update:
For noobs like me and don't know, use the NSLog methods as decribed below and make sure you select Run->Console to display the console.
Would still like to know if anyone has written a simple logger that displays on the iphone itself....
I don't have enough 'reputation' to add a direct comment for your posting but: don't forget to go to XCode->Preferences->Debugging->On Start: Choose Show Console & Debugger
You can of course choose just the Console or whatever, but you'll probably want the Debugger to. To use that, just click to the left of the line you want to break at. You can also toggle from 'Activate' to 'Deactivate' so you if you know that there are a bunch of breakpoints you don't need to hit in the beginning of your application set the debugging to Deactive (in the debugging window) and then, before you hit the UI element in your app you want to debug, toggle that same button to Activate so your breakpoints become active. Otherwise, you could of course just click Continue until you got to your section.
Also, on the NSLog, if you start to accumulate a bunch of log statements, and you need to 'find' one in particular, it helps to do: NSLog(#"\n\n\nMy statement\n\n\n); which will give a bunch of line breaks. Also, for the uninitiated:
NSLog(#"My int: %d my BOOL: %d", myInt, myBOOL);
NSLog(#"My object of any NSObject: %#", anObjectOfAnyKind);
NSLog(#"My float: %f",myFloat);
Hope all of this is helpful and sorry if I got off track with the debugging bit ;)
The Objective-C (more correct, really) method is
NSLog(#"message");
But the standard C method will work also
printf("message");
Use NSLog(#"Log message");
If your have an application that is crashing then your can ask the users you the crash log. The crash log contains information about what the application was doing when it crashed and the stack trace.
iPhone app log files are also stored on your users computer, and are copied across everytime they sync their iPhone. ( Note that DEVICE_NAME will be the same name of your iPhone in iTunes, and each log file will begin with the name of the app. )
Mac OS X : /Library/Logs/CrashReporter/MobileDevice//
Windows XP: C:\Documents and Settings\Application Data\Apple computer\Logs\CrashReporter\
Windows Vista: C:\Users\AppData\Roaming\Apple computer\Logs\CrashReporter\MobileDevice\
For Swift, it's simply
print("log msg")