我已经开发了一个使用异步图像视图和iCarousel.But的应用程序我的问题是,当我试图从urls加载图像时,只有活动指示器在我的iCarousel的每个视图中加载,没有图像是loaded.Here是我的代码
- (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;
}发布于 2012-11-01 17:37:05
遵循以下步骤可能是因为以下原因,您可能会遇到此问题
--检查您的imageURL数组是否包含iCarousel下的对象是否为空您可能会遇到这种问题...
--执行数组分配并添加对象
- (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-10-31 18:44:31
应该重用单元格
- (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;
}此外,您还应停止之前启动的
发布于 2013-09-20 22:37:40
- (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;
}https://stackoverflow.com/questions/13155874
复制相似问题