Flipkart Search

Search This Blog

Saturday, September 12, 2009

Upgrading your iPhone OS 2.0 Application to 3.0 and Handle Deprecation Warnings

The warnings I was getting are as follows:
warning: ’setImage:’ is deprecated (declared at /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/
iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/
Headers/UITableViewCell.h:199)
warning: ’setText:’ is deprecated (declared at /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/
iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/
Headers/UITableViewCell.h:199)
Before…


//This worked perfect in OS 2.0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *UserSettingButtonCellIdentifier = @"Cell";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UserSettingButtonCellIdentifier];
 if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: UserSettingButtonCellIdentifier] autorelease];
 }
     NSUInteger row = [indexPath row];
     UserSetting *rowData = [list objectAtIndex:row];
     UIImage *image = [UIImage imageNamed:@"MyImage.png"];
     if (row != 0)
         cell.image = image; //WARNING here
     cell.text = rowData.name; //WARNING here
     [rowData release];
     return cell;
}
//the tableView method is completely deprecated.
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
 return UITableViewCellAccessoryDisclosureIndicator;
}
After, doing the mods to get rid of the deprecated warnings:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 static NSString *UserSettingButtonCellIdentifier = @"Cell";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UserSettingButtonCellIdentifier];
 if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: UserSettingButtonCellIdentifier] autorelease];
 }
 NSUInteger row = [indexPath row];
 UserSetting *rowData = [list objectAtIndex:row];
 UIImage *image = [UIImage imageNamed:@"MyImage.png"];
 if (row != 0)
  cell.imageView.image = image; //FIXED here
 cell.textLabel.text = rowData.name; //FIXED here
 
#ifdef __IPHONE_3_0
        //This is a replacement for the tableView method
 cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
#endif
 
 [rowData release];
 return cell;
}
#ifndef __IPHONE_3_0
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
 return UITableViewCellAccessoryDisclosureIndicator;
}
#endif

1 comment:

StevenHWicker said...

This is a really informative knowledge, Thanks for posting this informative Information. IOS Developer