July 8, 2011, 8:51 pm
So I was looking for a way to easily run a block of Objective-C code after a set delay time. I found a few ways to do it, but one blog post I found encapsulated it pretty well. Here is the URL of that blog post:
Delayed Blocks in Objective-C
Using the NSObject category from the blog post, I can now run my block after a delay by using something like this:
[self performBlock:^{ [self myMethod]; } afterDelay:2.0f];
This will come in handy for my next blog post, which I will try to do over the weekend. (Hint: think of unrolling view hierarchies…)
BTW, Happy Birthday to Jack Lambert, one of the greatest Kent State alumni ever.
July 3, 2011, 12:29 pm
Well, I have finally released my Batter vs. Pitcher app that I have been working on for months now. The app is all about baseball statistics, so if you are a fan of baseball, please check it out:
Batter vs. Pitcher
BTW, Happy Birthday to John Kundla, former NBA coaching great. (I am not an NBA fan, but I could not find anyone I wanted to mention on the Wikipedia site for July 3, and his entry was the oldest on the births list that had not passed away.)
June 30, 2011, 12:57 pm
I found an awesome progress display that I have implemented in one of my iPhone apps. It is dead simple to use, does exactly what it should do and nothing more, and it is also open-source, which is good for developers on a budget like me.
This project by Matej Bukovinski is on github, here is the link:
MBProgressHUD
I found my way to this project through the awesome [iOS developer:tips]; web site, here is the link to their posting:
iOS Open Source : Heads Up Display with MBProgressHUD
BTW, Happy Birthday to Stanley Clarke. I have a ticket for when Return To Forever plays here in Columbus in August, I can’t wait.
June 29, 2011, 9:08 pm
Check out this code I was using for calculating text widths in my iPhone app’s PDF generator class (the first comment with the asterisks was added by me for this posting):
- (CGFloat)calculateTextWidth:(NSString *)text
{
// ********** do not use this method, see below for the fix **********
CGSize fullSize = [UIScreen mainScreen].applicationFrame.size;
UIGraphicsBeginImageContext(fullSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// calculate the text size
CGContextSelectFont(context, [fontName UTF8String], fontSize, kCGEncodingMacRoman);
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, -1.0));
CGContextSetTextDrawingMode(context, kCGTextInvisible);
// measure the text
CGPoint initialTextPosition = CGContextGetTextPosition(context);
CGContextShowTextAtPoint(context, 0, 0, [text cStringUsingEncoding:NSASCIIStringEncoding], text.length);
CGPoint finalTextPosition = CGContextGetTextPosition(context);
return finalTextPosition.x - initialTextPosition.x;
}
Pretty awesome, huh? Well, it worked awesome, my right justified text labels were all lining up great. The problem was that I could do one PDF in the app, maybe two, and the app would throw all kinds of memory warnings and then crash.
Well, as it turns out, it is a good idea to use a UIGraphicsEndImageContext() call when you use a UIGraphicsBeginImageContext() call. After I did this, all was right with the world.
Here is the finished product:
- (CGFloat)calculateTextWidth:(NSString *)text
{
CGSize fullSize = [UIScreen mainScreen].applicationFrame.size;
UIGraphicsBeginImageContext(fullSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// calculate the text size
CGContextSelectFont(context, [fontName UTF8String], fontSize, kCGEncodingMacRoman);
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, -1.0));
CGContextSetTextDrawingMode(context, kCGTextInvisible);
// measure the text
CGPoint initialTextPosition = CGContextGetTextPosition(context);
CGContextShowTextAtPoint(context, 0, 0, [text cStringUsingEncoding:NSASCIIStringEncoding], text.length);
CGPoint finalTextPosition = CGContextGetTextPosition(context);
UIGraphicsEndImageContext(); // !!!!!
return finalTextPosition.x - initialTextPosition.x;
}
BTW, Happy Birthday to Zuleikha Robinson. I miss the boys (and Yves, obviously) from The Lone Gunmen, I wish the show could have gone more than the 1/2 season it lasted.
June 23, 2011, 8:25 pm
Brian Prince gave a presentation on Windows Azure at the Central Ohio .NET Developer Group meeting on June 23, 2011. The presentation was mostly talking the process of moving existing applications to Azure, and the pitfalls that can arise when doing so. It was a very interesting presentation, and very appropriate since the company I am now working at is looking at creating some cloud based services.
BTW, Happy 99th Birthday to Alan Turing. OK, he is not currently among the living, but Happy Birthday to him nonetheless.
June 9, 2011, 1:10 pm
I have really been liking a couple of freeware iPhone, iPod touch, iPad, and iOS Simulator tools that I found. They both run great on my iMac, and are super simple to use, while providing some great missing functionality that the Xcode tools do not have.
The first is iPhone Explorer from Macroplant, which allows you to spelunk through the file system of a device connected to your system. It works with stock devices as well as jailbroken devices. Here is the link to download this application:
iPhone Explorer
The other tool is iOS-Simulator Cropper from Curious Times. This tool take screen shots from the iOS Simulator and, shockingly enough, automatically crops them down so that you can use them in your marketing materials or for uploading to the App Store. Here is the link to download this application:
iOS-Simulator Cropper
June 2, 2011, 4:53 pm
This is not so much a development issue as just a general usability issue, but it had frustrated me for a while and I am glad I got the issue behind me.
The problem was that my Garage Band v6 (2011 version) had some problems with the loops. When I would fire up the program, some of the loops in the loop browser showed up sort of grayed out with an arrow next to them. When I click on one of the grayed arrowed loops, I would get a message about how I needed to use Software Update to download the loops onto my computer. However, when I would go to Software Update, it would insist that there were no updates available. Also, when I went back into Garage Band to do the same thing again, it would respond with this message:
You have already initiated the installation of additional content for GarageBand via Software Update. For additional information please open the ‘Software Update’ application.
The battle of wits has begun.
Finally after trying to uninstall and reinstall a couple of times, and after looking through umpteen dozen posts on how this fixed it or that fixed it, I came upon this post on Apple’s web site:
Update the loop library
Finally I have slain the ROUS that was my loop browser issue.
May 31, 2011, 9:31 am
A friend of mine has created a new web site where Android developers can share their XML layouts that they have put together for Android applications. Here is the URL, be sure to check it out:
Android Layouts
May 29, 2011, 6:16 pm
The subject says it all. After trying to improve the responsiveness of my app by using a Grand Central Dispatch block to run some code asynchronously, the code in my main queue GCD block was failing with an objc_msgSend EXC_BAD_ACCESS error. Bugger.
The error itself typically describes sending a message to an object that has been released and is no longer valid, but I am not sure how that could have happened just by moving some operations inside of GCD blocks.
The way that I fixed this was to go into the diagnostics tab in the Edit Scheme window, and I turned on the Enabled Guard Malloc option. Then, when I ran the app, it showed me more specifically where the issue was. The problem turned out to be that I was using an autorelease array that was becoming invalid as a result of going into and coming out of the GCD blocks. I switched the array to a retained object, and everything started working fine again.
Just don’t forget to turn off the Enable Guard Malloc when you are done testing.
And if you have not yet checked out the coolness of Grand Central Dispatch, you are missing out on a valuable tool.
May 27, 2011, 12:45 pm
For some reason, my use of UIView’s sizeToFit method was not working as expected. What I got when I tried to send my UILabel controls through this method was that they ended up being sized down too far, and as a result text was either eliminated from the label, or an ellipsis appeared at the end. I tried just about every combination of UILineBreakMode and numberOfLines I could think of, with no combination fixing the problem.
So what I ended up doing was to just manipulate the UILabel’s frame in the table view’s cellForRowAtIndexPath method. Here is a code snippet:
if (feedIndex == SECTION_CUSTOMER_AND_JOB_INFO)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELL_CUSTOMER_AND_JOB_INFO];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"SummaryCustomerAndJobInfoCell" owner:self options:NULL];
cell = cellCustomerAndJobInfo;
}
// the next line uses the tag property of the label as set in the nib file
UILabel *lbl = (UILabel *)[cell viewWithTag:1];
NSString *text = @"Set your multiple line\ntext to display here...";
CGSize constraint = CGSizeMake(lbl.frame.size.width, 20000.0f);
CGSize size = [text sizeWithFont:lbl.font constrainedToSize:constraint
lineBreakMode:UILineBreakModeWordWrap];
lbl.text = text;
[lbl setFrame:CGRectMake(lbl.frame.origin.x, lbl.frame.origin.y,
lbl.frame.size.width, size.height)];
return cell;
}
By the way, don’t forget to do the same kind of size calculations in your heightForRowAtIndexPath delegate method.
This past Wednesday was a day of great sadness for me, as I had to put my 15 year old schipperke to sleep. Good bye Captain Kirk, you were an ornery little cuss but we loved you anyway. :’(