[英]how to change custom UIImageView when table view cell is selected
我正在使用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];
}
}
您可以為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;
}
-(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"]];
}
OtherWise代替圖像,您可以使用UIButton並更改按鈕的狀態,我們在上面的代碼中的Image視圖上更改了圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.