5

AsyncimageviewとiCarouselを使用するアプリを開発しましたが、URLから画像を読み込もうとすると、アクティビティインジケーターのみがiCarouselの各ビューに読み込まれ、画像は読み込まれません。コードは次のとおりです。

  - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(AsyncImageView *)view
 {
if (view == nil
 {
  AsyncImageView * view = [[[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 280)] autorelease];
view.image=[UIImage imageNamed:@"infobg.png"];
view.imageURL=[imageURLs objectAtIndex:index];
}
return view;
}
4

4 に答える 4

2

この問題に直面する可能性がある次の理由により、次の手順に従ってください

-- ur imageURLs 配列が iCarousel の下にオブジェクトを持っているかどうかを確認してください...その null の場合、この種の問題が発生している可能性があります....

-- 配列の割り当てを行い、オブジェクトを追加します

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 

viewDidLoad の下の配列にオブジェクトを追加すると、viewDidLoad メソッドの前にカルーセル ビューが最初に読み込まれるため、機能しません。

-- これらの手順の後でも配列要素が存在する場合は、このコードに従います。

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(AsyncImageView *)view
{
view = [[[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 280)] autorelease];

view.image=[UIImage imageNamed:@"infobg.png"];
view.imageURL=[imageURLs objectAtIndex:index];

//NSLog(@"%@",imageURLs)//check imageURLs having object

if(view ==nil)
{
    [[AsyncImageLoader sharedLoader]cancelLoadingImagesForTarget:view];
}
return view;

}

それはあなたを助ける..

于 2012-11-01T09:37:05.027 に答える
2

セルは再利用する必要があります

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(AsyncImageView *)view

 {
if (view == nil) {
 view = [[[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 280)] autorelease];
}
// dont forget stop previous loading -cancelLoadingURL:target:

 view.image=[UIImage imageNamed:@"infobg.png"];
 view.imageURL=[imageURLs objectAtIndex:index];

 return view;
}

また、以前に開始したのを停止する必要があります

于 2012-10-31T10:44:30.567 に答える
1
- (void)viewDidLoad
{
    [super viewDidLoad];

    User_Id=@"abcd@gmail.com";

    NSString *Post=[NSString stringWithFormat:@"email=%@",User_Id];
    NSData *PostData = [Post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
    NSString *PostLengh=[NSString stringWithFormat:@"%d",[Post length]];
    NSURL *Url=[NSURL URLWithString:[NSString stringWithFormat:@"%@fetch_all_user_updates.php",ServerPath]];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:Url     cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    [request setHTTPMethod:@"POST"];
    [request setValue:PostLengh forHTTPHeaderField:@"Content-Lenght"];
    [request setHTTPBody:PostData];

    NSData *ReturnData =[NSURLConnection sendSynchronousRequest:request returningResponse:Nil error:Nil];
    NSString *Response = [[NSString alloc] initWithData:ReturnData encoding:NSUTF8StringEncoding];
    Response = [Response stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSMutableArray *JSON_Array=[Response JSONValue];

// NSlog(@"%@", JSON_Array);
// textfield.text=[[JSON_Array valueforKey:@"email"]objectAtIndex:0];
// load images from database at local host
/*
NSLog(@"%@",[NSString stringWithFormat:@"%@/Images/%@",serverScriptpath,[[jsonarray valueForKey:@"image"]objectAtIndex:0]]);
NSURL *img_url=[NSURL URLWithString:[NSString stringWithFormat:@"%@/Images/%@",
                                     serverScriptpath,[[jsonarray valueForKey:@"image"]objectAtIndex:0]]];

NSURLRequest *request1=[NSURLRequest requestWithURL:img_url];
[Img_profilepic setImageWithURLRequest:request1 placeholderImage:[UIImage imageNamed:@".png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {

} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {

}];
*/


    if (JSON_Array>0)
    {
        Array_Image_Name=[JSON_Array valueForKey:@"image_name"];
        [Array_Image_Name retain];
    }
    else
    {
        UIAlertView *Alert=[[UIAlertView alloc]initWithTitle:@"Failure" message:@"Error To Load Image" delegate:Nil cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil];
        [Alert show];
        [Alert release];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return Array_Image_Name.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell;
    cell=nil;
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    AsyncImageView *Load_Image=[[AsyncImageView alloc]initWithFrame:CGRectMake(20, 10, 280, 100)];
    Load_Image.imageURL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/Images/%@",ServerPath,[Array_Image_Name objectAtIndex:indexPath.row]]];
    Load_Image.showActivityIndicator=YES;
    [cell.contentView addSubview:Load_Image];
    return cell;
}
于 2013-09-20T14:37:40.030 に答える
0
AsyncImageView *asyncImage = [[AsyncImageView alloc] initWithFrame:CGRectMake(0.0f, 1.0f, 320.0f, 174.0f)];
NSString *imgUrlString = photobig1;
while ([imgUrlString rangeOfString:@" "].location != NSNotFound) {
    imgUrlString = [imgUrlString stringByReplacingOccurrencesOfString:@" " withString:@""];
}
UIImageView *imageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Loading Image.png"]];
[asyncImage addSubview:imageview];
asyncImage.tag = 999;
NSString *webStr = [NSString stringWithFormat:@"%@",imgUrlString];
NSURL *imageUrl = [[NSURL alloc] initWithString:[webStr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[asyncImage loadImageFromURL:imageUrl];
[asyncImage setBackgroundColor:[UIColor clearColor]];
asyncImage.userInteractionEnabled = NO;

  [scrollView addSubview:asyncImage];
于 2014-03-18T07:56:47.653 に答える