1

次の機能が必要なアプリを開発しています。

  1. サーバーから複数の画像ファイルをダウンロードします。
  2. グリッド形式で表示します。

上記の要件を満たすために、

.xib ファイルでカスタム ビューを作成しました。それをスクロールビューに追加しました。

しかし、画像を非同期にダウンロードして適切な場所に表示する方法についてはわかりません。

グリッド スタイルでカスタム ビューを追加するための私のコードはこちらです。

-(void)LazyLoading_display_Objects_in_grid_style
{

    for(int i=0; i<[imageListingArray count] ; i++)
    {
        NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:nil options:nil];
        MyView *myView = (MyView *)[arr objectAtIndex:0];
        myView.frame = CGRectMake(x,y,width,height);
myView.imgPhoto setContentMode:UIViewContentModeScaleAspectFit];
        myView.imageURL = [NSString stringWithFormat:@"%@",[[imageListingArray objectAtIndex:i] valueForKey:@"name"]];
 [myView setBackgroundColor:[UIColor clearColor]];

        if(myView.imgPhoto.image == nil)
            [myView.actLoading startAnimating];

        [myView.imgPhoto setTag:1000+i];

        [myView setUserInteractionEnabled:TRUE];
        myView.tag = 100+i;

        [self.imageListingScrollView addSubview:myView];

        if(current_no_of_object_in_row !=noOfObjectInColumn)
        {
            x =x + width + 8 ;
            current_no_of_object_in_row ++;
        }
        else
        {
            current_no_of_object_in_row =1;
            x = 5;
            y = y+ height + 8 ;
        }
        scrollView_Height = y;
    }
int temp = [imageListingArray count]%noOfObjectInColumn;

    if(temp>0)
    {
        NSLog(@"No modulus");
        y = y + height+ 10;
    }
    scrollView_Height = y;
    NSLog(@"Scroll Height : %d",scrollView_Height);
    [self.imageListingScrollView setContentSize:CGSizeMake(308, scrollView_Height+ 5)];
}
4

3 に答える 3

1

AsyncImageViewクラスの使用を試みることができます。これはUIImageの拡張機能であり、直接URLからの非同期ダウンロード画像を可能にします。私は多くのプロジェクトで同様の拡張機能を使用しています。メソッドを呼び出すだけです

- (void)loadImageWithURL:(NSURL *)URL;

データが取得されると、このビューに画像が表示されます。 https://github.com/nicklockwood/AsyncImageView

また、すべてのiOS用のUITableViewのiOS 6以降用のプロジェクトを作成する場合は、UICollectionViewクラスを使用して作成できるグリッド。UITableViewを使用する場合は、左側と右側に2つのAsyncImageViewオブジェクトを含むカスタムセルを作成できます。

于 2013-01-08T10:08:04.327 に答える
1

複数のビューを作成する代わりに、UITableView を使用できます。UIScrollViews と Grid ディスプレイの両方として機能します。このリンクはあなたを助けるかもしれません:

http://www.markj.net/iphone-asynchronous-table-image/ http://davidgolightly.blogspot.in/2009/02/asynchronous-image-caching-with-iphone.html https://developer.apple .com/library/ios/#samplecode/LazyTableImages/はじめに/Intro.html

于 2013-01-08T07:07:54.787 に答える
1

UITableView インスタンスを取得し、次のように回転させます。

CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2.0f);    
table.transform = transform;  

同様に、UITableView内のセルを回転させる必要がある場合もあります

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2.0f);
  cell.transform = transform;
}

そのようにUIScrollViewを取得する場合、メモリを処理する必要があるため、myquestionをチェックアウトできます

于 2013-01-08T07:18:08.317 に答える