2014-07-05 1 views
0

J'affiche plusieurs images dans un UITableViewCell comme une image miniature. Mais j'ai du mal à récupérer l'image de UITableViewCell sélectionné. Je dois le faire pour afficher l'image dans un autre ViewController. J'ai vraiment du mal à résoudre ce problème.Comment faire pour récupérer l'image miniature de UITableViewCell

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyCell"]; 
    if (cell==nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"]; 

    } 

    jsonDict = [jsonArr objectAtIndex:indexPath.row]; 
    //NSLog(@"imagess%@",jsonDict); 
    cell.textLabel.text = [jsonDict objectForKey:@"ImageName"]; 

    stringg=[NSString stringWithFormat:@"%@",cell.textLabel.text]; 

    cell.textLabel.textAlignment=NSTextAlignmentCenter; 


     NSData *imgData = [NSData dataWithBase64EncodedString:[jsonDict objectForKey:@"ImageData"]]; 

     imageView.image=[UIImage imageWithData:imgData]; 
    } 
    return cell; 

} 



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    NSLog(@"%@",cell); 

    NSString *textname=[NSString stringWithFormat:@"%@",cell.textLabel.text]; 
    NSLog(@"%@",textname); 
UIImage *image1 =selectedCell.imageView.image; 
     age.ageimgae=image1; 
} 
+0

ont u montrent la capture d'écran de la page et le code pour l'image en cellforatindexpath et didselectrowatindexpath –

+0

vérifier maintenant ... @ Anbu.Karthik –

+0

avez-vous voir la capture d'écran de la page –

Répondre

0

Dans didSelectRowAtIndexPath u besoin d'identifier le Indexpath particulier

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
jsonDict = [jsonArr objectAtIndex:indexPath.row]; 

NSLog(@"the textr Name==%@",[jsonDict objectForKey:@"ImageName"]); 

    UIImage *image1 = [UIImage imageWithData:[NSData dataWithBase64EncodedString:[jsonDict objectForKey:@"ImageData"]]]; 


NSData *imageData = UIImagePNGRepresentation(image1); 
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"imageDataKey"]; 
[[NSUserDefaults standardUserDefaults]synchronize]; 
NSLog (@"Data Saved"); 


} 

ici votre choix u passer e e NSData ou votre image à un autre contrôleur de vue à l'aide NSUSerdefault ou singleton ou SharedInstance, autre chose ..

dans secondviewcontroler.m

nsdata *imagedata=[[NSUserDefaults standardUserDefaults] [email protected]"imageDataKey"]; 

    yourimgaename.image = [UIImage imageWithData:[NSData dataWithBase64EncodedString: imagedata]]; 
1

lieu d'aller chercher l'image de la cellule sélectionnée, vous pouvez utiliser l'index de la cellule sélectionnée afin de récupérer l'image requise dans votre JSonArray (comme vous l'avez fait dans votre tableView cellForRowAtIndexPath:):

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    jsonDict = [jsonArr objectAtIndex:indexPath.row]; 
    NSData *imgData = [NSData dataWithBase64EncodedString:[jsonDict objectForKey:@"ImageData"]]; 
    UIImage *image1 = [UIImage imageWithData:imgData]; 
} 
Questions connexes