我正在使用带有uitableview的自定义单元格。在单元中,我有一个uiimage和一个带标签.when,当我在自定义单元中加载所有未选择的图像时,我正在加载表格视图。现在我想当用户选项卡一个单元格的时候想要改变图像(选定的图像)。之后,它将进入另一个视图控制器,但当用户到来时,他可以看到带有选定图像图标的选定单元格。
- (void)viewDidLoad {
[super viewDidLoad];
title=[[NSArray alloc]initWithObjects:@"Hi one ", @"one ",@"one ACCOUNT ",@"one A SEVICE",@"one YOUR ORDER",@"one FREE SERVICE",@" one WALL",@"one POINTS", @"one LOCATOR",@"one WITH US",@"one_ PACKAGE",@"one_call",nil];
imgicon=[[NSArray alloc]initWithObjects:@"profile_icon.png",@"db_icon.png",@"ma_icon.png",@"pickup_icon.png",
@"ic_track_nav.9.png",@"rf_icon.png",@"wal_icon.png",@"ic_loylty_nav.9.png",@"ic__locator.9.png",@"ic_nification.png",@"kage_icon.png",@"ic_reachus.png",nil];
imgiconselected=[[NSArray alloc]initWithObjects:@"profile_icon.png",@"db_icon_p.png",@"ma_icon_p.png",@"pickup_icon_p.png",
@"ic_track_nav.9_p.png",@"rf_icon_p.png",@"wa_icon_p.png",@"ic_loya_nav.9_p.png",@"ic__locator.9_p.png",@"ic_notification_p.png",@"pge_icon_p.png",@"ic_reacs_p.png",nil];
[slidertb reloadData];
// Do any additional setup after loading the view.
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// here how can i get that cell path and icon image to change .
NSLog(@"row==%ld",(long)indexPath.row);
if(indexPath.row==1){
FroVC *froVC = [self.storyboard instantiateViewControllerWithIdentifier:@"froVC"];
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: @[froVC] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
}发布于 2015-09-28 21:24:06
您可以为您的UITableViewCell实现- (void)setSelected:(BOOL)selected方法。在此方法中,您可以根据selected状态更改ImageView。
如果您希望在用户未从单元格释放手指时进行此更改,您可以使用- (void)setHighlighted:(BOOL)highlighted方法。
更新。示例:
// code inside your UITableViewCell.m
- (void)setSelected:(BOOL)selected {
[super setSelected: selected];
_myAwesomeImageView.highglighted = selected;
}发布于 2015-09-28 23:37:49
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Get cell here, which index path cell image you need to change
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// set image for selected state
[cell setImage:[UIImage ImagedName:@"imageName"]];
}在图像的位置,你可以使用UIButton并改变按钮的状态,我们在上面的代码中改变了图像视图中的图像。
https://stackoverflow.com/questions/32823539
复制相似问题