简体   繁体   English

当选择表格视图单元格时如何更改自定义UIImageView

[英]how to change custom UIImageView when table view cell is selected

i am using custom cell with uitableview . 我正在使用uitableview自定义单元格。 In cell i have one uiimage and a lable .when i am loading table view that time i am loading all unselected image in custom cell . 在单元格中,我有一个uiimage和一个标签。当我加载表格视图时,我正在将所有未选中的图像加载到自定义单元格中。 now i want when user tab a cell at that time want to change image (selected image). 现在我想当用户在一个选项卡上的某个时间想要更改图像(选定的图像)时。 after that its going in an other view contoller but when user coming he can see selected cell with selected image icon. 之后,它会进入另一个视图控制器,但是当用户来时,他可以看到带有选定图像图标的选定单元格。

- (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];
    }



}

You can implement - (void)setSelected:(BOOL)selected method for your UITableViewCell. 您可以为UITableViewCell实现- (void)setSelected:(BOOL)selected方法。 Inside this method you can change your ImageView according to selected state. 在此方法内,您可以根据selected状态更改ImageView。

If you want this changes while user didn't release finger from cell you can use - (void)setHighlighted:(BOOL)highlighted method. 如果您希望在用户没有从单元格中释放手指时进行此更改,则可以使用- (void)setHighlighted:(BOOL)highlighted方法。

UPD. UPD。 Example: 例:

// 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 in place of image you can take UIButton and change the state of button as same, we are changing the image on Image view in above code. OtherWise代替图像,您可以使用UIButton并更改按钮的状态,我们在上面的代码中的Image视图上更改了图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM