uitableviewcell imageview图像在启动时未显示

时间:2013-11-01 16:47:32

标签: objective-c uitableview uiimageview ios7 afnetworking

所以我在我的viewdidLoad中使用UIImageView + AFNetwrking从Api和我的cellforRowAtIndexPath方法下载我的图像,使用setImageWithUrl方法设置每个单元格的图像视图图像,但图像并不都直接出现在控制器之后负荷。

只有当我在My tableView中选择一个单元格时,我的每个单元格中才会显示每个图像imageView。

如何在视图加载后直接在我的单元格中显示图像。

这里是我的uitableviewcell子类

@implementation UIMeCell
@synthesize MoveObject=_MoveObject;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
    // Initialization code
    self.textLabel.adjustsFontSizeToFitWidth = YES;
    self.textLabel.numberOfLines = 0;
    self.textLabel.textColor = [UIColor blackColor];
    self.textLabel.textAlignment = NSTextAlignmentLeft;
    self.textLabel.font = [UIFont systemFontOfSize:12.0f];
    self.selectionStyle = UITableViewCellSelectionStyleGray;
 }
return self;
}
-(void)setMoveObject:(UIMoveObject *)MoveObject{
_MoveObject = MoveObject;
self.textLabel.text = self.MoveObject.MovieTitle;
 [self.imageView setImageWithURL:[NSURL URLWithString:_MoveObject.MoviePoster] placeholderImage:       
[UIImage imageNamed:@"image"]];
    [self setNeedsDisplay];

 }
-(void)layoutSubviews{
 [super layoutSubviews];
 self.imageView.frame = CGRectMake(0,0,32,32);
 }

我的ViewController类

- (void)viewDidLoad
{   
    [super viewDidLoad];
    self.baseUrls = base_rr;


 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

 [theTableView registerClass:[UIMeCell class] forCellReuseIdentifier:@"Cell"];
[theTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];


[self refresh]; 
}
-(void)refresh{
self.MovieArray = [[NSMutableArray alloc] init];
theNavigationItem.rightBarButtonItem.enabled = NO;
NSURLSessionDataTask * task = [UIFlickConnect MovieListWithUrl:TOP_Rated andParameters:   
[NSDictionary dictionaryWithObjectsAndKeys:API_KEY,@"api_key", nil] andBlock:^(NSArray* err,    
NSError *error) {
    if (!error) {
        self.MovieArray = [err mutableCopy];
              [theTableView reloadData];
         theNavigationItem.rightBarButtonItem.enabled = YES;
}
}];

[UIAlertView showAlertViewForTaskWithErrorOnCompletion:task delegate:nil];

UIActivityIndicatorView *activityIndicatorView = (UIActivityIndicatorView *)    
theNavigationItem.rightBarButtonItem.customView;
[activityIndicatorView setAnimatingWithStateOfTask:task];

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    
 *)indexPath{
NSString *cellidentifier  = @"Cell";
UIMeCell *cell;
cell = [theTableView dequeueReusableCellWithIdentifier:cellidentifier forIndexPath:indexPath];
if (!cell) {
    cell = [[UIMeCell alloc] initWithStyle:UITableViewCellStyleDefault      
 reuseIdentifier:cellidentifier];
}

NSMutableDictionary * dictionary  = [[self.MovieArray objectAtIndex:indexPath.row] mutableCopy];
[dic setValue:[self.baseUrls stringByAppendingString:dic[@"poster_path"]]     
forKey:@"poster_path"];

UIMoveObject * object = [[UIMoveObject alloc] initWithDictionary:dictionary];
cell.MoveObject = object;


return cell;
}

0 个答案:

没有答案