Let’s say you have an UITableView in which rows, when touched, changes the display to another view with an animation.
If you touch quickly a row, the row will highlight just before the animation starts.
Let’s say you have an UITableView in which rows, when touched, changes the display to another view with an animation.
If you touch quickly a row, the row will highlight just before the animation starts.
In my current project, I needed to know if a given NSDate was today, yesterday or earlier. Simple task, I thought. Until I looked at the documentation for NSCalendar, NSDateComponents and NSDate. While these are extremely powerful, I am not proud of the code I’ve written. It should be easier.
Anyway, the code below will take a date and return a formatted version relative from today:
A beta-tester was complaining the application was draining its battery. To check if this was really the case, I needed to get the battery level with a better accuracy than just looking at the battery icon. So I used this little routine to check.
This routine is adapted from a post on MacRumors.com.
If you need to debug your app when disconnected from your Mac (and from the console), redirect all your NSLog calls to a file so you can later read it.
The method below will create a file name « console.log » in the Documents folder of your application so you can later read it.
Just call this method in your program:
- (void) redirectConsoleLogToDocumentFolder
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *logPath = [documentsDirectory
stringByAppendingPathComponent:@"console.log"];
freopen([logPath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}
The log will never be erased, so use with caution.
These are some of the macros I use with Xcode:
CMLog: I use this macro to replace NSLog:
#define CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]);
When you use this macro, it outputs text to the console, including the class and method from where it was called. So, if you call this macro from the class MyAppDelegate and the method applicationDidFinishLaunching,
CMLog(@"My iPhone is an %@, v %@", [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]);
you get this in the console:
If, like me, you want to make sure your text will fit inside your UIWebView (without scrolling), you can implement the following javascript:
<script language='javascript' type="text/javascript">
function adjustHeight(maxHeight) {
elem = document.getElementById("sign");
height = elem.offsetHeight;
current_size = elem.style.fontSize.replace('px','')/1;
while ((current_size-- > 10) && (height > maxHeight)){
elem.style.fontSize = current_size + 'px';
height = elem.offsetHeight;
}
}
</script>
I needed to select an UITabBarItem located in the « More… » section, and I came to this solution:
To select a viewController of the tabBarController, I do the following (each tabBarItem has a tag) :
This snippet shows how to add an UIProgressView to an UIAlertView.
You can choose to display an UIProgressView or an UIActivityIndicatorView in the alert.
This may break with a new version of the SDK (2.1 for now), but this was accepted by Apple (or they didnt see it)
When I bought my iMac, I did a restore from my MacBook TimeMachine backup. When I continued working on my current project, I did notice a difference between the files that were on my MacBook and the files on my iMac. The files restored from the backup were not up-to-date and were from a few days ago.
I tried this snippet on MacOSXHints to compare Time Machine backups to the original drive, and it found differences between the original disk and the backup.