Tuesday, September 7, 2010

change BackGround Image of Cell on selection in TableView in objective C (Iphone)

using below function we can change Backgroundimage of cell/row when user click/select on row/cell of tableview in objective-C


- (void)tableView:(UITableView *)tableView

didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSArray *listData =[self.tableContents objectForKey:

[self.sortedKeys objectAtIndex:[indexPath section]]];

NSUInteger row = [indexPath row];

NSString *rowValue = [listData objectAtIndex:row];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.backgroundView = [[[UIImageView alloc] init] autorelease];
cell.selectedBackgroundView = [[[UIImageView alloc]init] autorelease];
((UIImageView *) cell.backgroundView).image = [UIImage imageNamed:@"checkbox-checked.png"];
((UIImageView *) cell.selectedBackgroundView).image = [UIImage imageNamed:@"checkbox-checked.png"];


[tableView deselectRowAtIndexPath:indexPath animated:YES];

}


Solution By: Rajesh Rolen

No comments:

Post a Comment