2012-12-03 2 views
2

Je reçois les images à partir des services Web dans la vue de liste, mais je veux les montrer dans la grille voir. Comme j'affiche les images dans la vue de liste, dans la vue de grille comment je peux faire ceci? S'il vous plaît help.this ressemble à mon code ressemble: -comment afficher des images à partir de services Web dans la vue de la grille

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSString *[email protected]"CELL"; 
    UITableViewCell *cell=nil; 
    if (cell==nil) { 

     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CELLIDENTIFIER] autorelease]; 
     CGRect imageFrame = CGRectMake(2, 8, 80, 60); 
     NSURL *url = [NSURL URLWithString:[arrayListG objectAtIndex: [indexPath row]]]; 
     NSData *data = [NSData dataWithContentsOfURL:url]; 
     UIImage *img = [[[UIImage alloc] initWithData:data] autorelease]; 
     UIImageView *customImage = [[[UIImageView alloc] initWithFrame:imageFrame] autorelease]; 

     customImage.image=img; 
     [cell.contentView addSubview:customImage]; 
    } 

    return cell; 
} 
+0

Voulez-vous dire TableView avec des lignes en elle comme vue Grille? –

+0

yes..i signifie la même chose .. – Shivaay

+1

Pourquoi ne pas utiliser une vue déroulante pour afficher vos images dans une grille. comment les images voulez-vous montrer dans une rangée? –

Répondre

1
Gridview = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];//your frame   
Gridview.backgroundColor=[UIColor clearColor]; 
int row=0; 
int column=0; 
int rows=4; 
int cols=5; 
for (int i=0; i<rows*cols; i++) 
{ 
    if((row%4==0)&&(row>0)) 
    { 
     row=0; 
     column++; 
    } 
    else{ 
     row++; 
    } 
CGRect imageFrame = CGRectMake(row*80+10, column*60+10, 80, 60);//your imageview frame 
    NSURL *url = [NSURL URLWithString:[arrayListG objectAtIndex:i]]; 
    NSData *data = [NSData dataWithContentsOfURL:url]; 
    UIImage *img = [[[UIImage alloc] initWithData:data] autorelease]; 
    UIImageView *customImage = [[[UIImageView alloc] initWithFrame:imageFrame] autorelease]; 

    customImage.image=img; 
    [Gridview addSubView:customImage]; 

} 
[Gridview setContentSize:CGSizeMake(rows*90, cols*70)]; 

Gridview est votre scrollview ajouter dans IB ou programatically que vous le désirez dans mon cas je l'ai ajouté programatically. définir la taille du contenu et le cadre selon vos besoins

0

S'il vous plaît modifier votre code ci-dessous.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSString *[email protected]"CELL"; 
    UITableViewCell *cell=nil; 
    if (cell==nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CELLIDENTIFIER]; 

     CGRect imageFrame = CGRectMake(2, 8, 80, 60); 
     UIImageView *customImage = [[UIImageView alloc] initWithFrame:imageFrame]; 
     customImage.tag = 1; 
     [cell.contentView addSubview:customImage]; 
    } 
    UIImageView *customImage = (UIImageView *)[cell viewWithTag:1]; 

    NSURL *url = [NSURL URLWithString:[arrayListG objectAtIndex: [indexPath row]]]; 
    NSData *data = [NSData dataWithContentsOfURL:url]; 
    UIImage *img = [[UIImage alloc] initWithData:data]; 
    customImage.image =img; 

    return cell; 
} 
2

Mieux vaut utiliser cette bibliothèque impressionnante pour gridview Comment mettre en œuvre et d'intégrer dans tout projet est documenté sur ce lien. check this out AQGridview

Questions connexes