views:

1763

answers:

7

I just installed iPhone SDK 3.0 and found that the text property of UITableViewCell is not used anymore, and should use textLabel.text instead. Does this mean that I have to know the current system version and call the corresponding method? like this.

UITableViewCell *cell = ...;
if ([[[UIDevice currentDevice] systemVersion] isEqualToString:@"3.0"]) {
  cell.textLabel.text = @"...";
} else {
  cell.text = @"...";
}

If so, that would be very annoying.

+1  A: 

You can use the 3.0 SDK and target an older version on your projects, like 2.2 or 2.2.1.

To do so, you set the Base SDK to 3.0 but change the iPhone OS Deployment Target setting. Both settings are accesible if you Get Info on the project.

pgb
A: 

Actually, I don't think you have to do this because when you build your project, you choose what firmware it is targetted to, like pgb mentioned. Then you can simply use #ifdef directives. Here is more information: http://stackoverflow.com/questions/845733/iphone-check-firmware-version A much more thorough answer is posted here: http://stackoverflow.com/questions/820142/how-to-target-a-specific-iphone-version

EDIT: I removed some text after realizing that systemVersion is actually a string, source: UIDevice Docs.

If you will use it in various files across your project then you can maybe organize it by adding it as a property to your appdelegate, and them retrieving the value by doing something like this:

MyAppDelegate *theDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *version = theDelegate.version;

But that might be too convoluted for something so simple as the version number.

Jorge Israel Peña
+3  A: 

Just build for 3.0 and don't worry about 2.2 anymore. Unlike major OS upgrades, people have been upgrading to new version of iPhone OS very, very quickly. Check out this post on the TapBots blog: iPhone 3.0 Adoption Rate.

By the time your app gets approved (2 weeks from now + some?) almost nobody will be using 2.2 anymore!

Ben Gotow
hi this can be used to devlop universal application http://cocoabugs.blogspot.com/2010/09/utility-method-to-know-ios4-installed.html
jeeva
+4  A: 

Instead of checking the OS version, you can check if the cell has the new property:

if ([cell respondsToSelector:@selector(textLabel)]) {
  // Do it the 3.0 way
  cell.textLabel.text = @"...";
} else {
  // Do it the 2.2 way, but avoid deprecation warning
  [cell performSelector:@selector(setText:) withObject:@"..."];
}
Chris Lundie
+1  A: 

It's deprecated and they suggest the new way, but you certainly can still use the 2.2 way if you want and it won't negatively affect your app running on 3.0. If you're concerned about users still on 2.2 definitely check the link ben provided. I don't think it'll be a big deal if you compile for 3.0.

Kevlar
A: 

If you decide to stick with 2.2 for now, be sure to test in the simulator with 3.0. We've seen odd behavioral differences between 2.2 and 3.0, especially with tables.

Steve Riggins
A: 

I find nice utility method in this link
http://cocoabugs.blogspot.com/2010/09/utility-method-to-know-ios4-installed.html

jeeva
In general I think you're better checking for the availability of specific classes or methods (as Chris Lundie mentions) rather checking the version number.
Stephen Darlington