简体   繁体   中英

iPhone SDK 3.0 Vs. 2.2.1

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.

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:@"..."];
}

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!

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.

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.

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: iPhone check firmware version A much more thorough answer is posted here: 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM