tableviewcell里面imageview在下载图片之前显示loading,下载后显示指定图片

tableView:cellForRowAtIndexPath委托里面定义一个 UIActivityIndicatorView 添加到cell.imageview并启动。


UIActivityIndicatorView *activeIndicatorView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

[cell.imageView addSubview:activeIndicatorView];//[UIImage imageNamed:@"process.png"];

[activeIndicatorView release];

[[cell.imageView.subviews lastObject]  startAnimating];

[[cell.imageView.subviews lastObjectsetFrame:CGRectMake(5075,50,50)];

cell.imageView.image = [UIImage imageNamed:@"bg.jpg"];//设置一个default图片,要不然activityindicator不会显示



在下载完成图片的事件中移除subview,指定下载后的图片显示


移除添加uiactiveityindicatorview

[[cell.imageView.subviews lastObjectremoveFromSuperview];

或者移除所有subview

[[cell.imageView subviewsmakeObjectsPerformSelector:@selector(removeFromSuperview)];


你可能感兴趣的:(iPhone,开发)