0

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

只有当我在我的 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;
}
4

0 回答 0