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

时间:2015-09-28 12:54:54

标签: ios objective-c uitableview uiimageview

我正在使用带有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];
    }



}

2 个答案:

答案 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并更改按钮的状态,我们正在上面的代码中更改图像视图中的图像。