我正在使用带有uitableview的自定义单元格。在单元格中我有一个uiimage和一个标签。当我加载表视图时,我正在加载自定义单元格中的所有未选择的图像。现在我想要当用户选项卡当时的单元格想要更改图像(所选图像)。之后,它进入另一个视图控制器,但当用户来时,他可以看到选定图像图标的选定单元格。
- (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];
}
}
答案 0 :(得分:0)
您可以为UITableViewCell实施- (void)setSelected:(BOOL)selected
方法。在此方法中,您可以根据selected
状态更改ImageView。
如果您希望在用户未从单元格释放手指时进行此更改,则可以使用- (void)setHighlighted:(BOOL)highlighted
方法。
UPD。示例:
// code inside your UITableViewCell.m
- (void)setSelected:(BOOL)selected {
[super setSelected: selected];
_myAwesomeImageView.highglighted = selected;
}
答案 1 :(得分:0)
-(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并更改按钮的状态,我们正在上面的代码中更改图像视图中的图像。