2014-07-05 31 views
0

我在UITableViewCell中显示多个图像,如缩略图图像。但我很努力地检索选定的UITableViewCell的图像。我必须这样做才能在另一个ViewController中显示图像。我真的很努力解决这个问题。如何检索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

图像使用NSUSerdefaultsingletonSharedInstance,别的另一个视图控制器..

有u显示页面中cellforatindexpath的屏幕截图和代码的图像和didselectrowatindexpath –

+0

立即检查... @ Anbu.Karthik –

+0

让你显示页面的截图 –

回答

0

didSelectRowAtIndexPath u需要在这里识别特定Indexpath

-(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"); 


} 

您选择ú个通过Ë的NSData或者您在secondviewcontroler.m

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

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

而是获取选定单元格的形象,你可以使用所选单元格的索引,才能在JSonArray(就像你在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]; 
}