Я показываю данные в UITableView с миниатюрным изображением. Изначально, когда на ячейку нажимают, я перезагружаю изображение с сервера, на которое потребуется дополнительное время, ресурсы и память. Вместо этого я подумал о передаче указателя миниатюрного изображения в представление, которое будет отображаться на экране, и сразу же отобразить его, вместо того, чтобы его повторно загрузить. Тем не менее, я столкнулся с проблемой - ничего не загружается, когда я устанавливаю imageView на новом представлении на старое изображение. Вот мой код:Изображение не загружается на UIImageView
Это в моем UITableView Класс:
CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
NewsViewController *newsViewController = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil dictionary: dict type:d numberOfPages:1 image: cell.imageView.image];
NewsViewController.m:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dictionary:(NSDictionary *)dict type:(NSInteger)type numberOfPages:(NSInteger)pages image:(UIImage *)image{
self = [super initWithNibName:@"NewsViewController" bundle:Nil];
if (self) {
newsText = [dict objectForKey:@"content"];
newsTitle = [dict objectForKey:@"title"];
newsDate = [dict objectForKey:@"pub_date"];
d = type;
numberOfPages = pages;
imageURL = [[NSMutableArray alloc] initWithCapacity:numberOfPages];
mainImage = [[UIImage alloc] init];
mainImage = image;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
labelBody.text= newsText;
titleView.text = newsTitle;
date.text = newsDate;
if (numberOfPages == 1) {
imageScrollView.contentSize = CGSizeMake(320, 303);
pageControl.numberOfPages = 1;
CustomImageView *customImageView = [[CustomImageView alloc] initWithFrame:imageScrollView.bounds];
[imageScrollView addSubview:customImageView];
customImageView.imageView.image = mainImage;
}
}
NewsViewController.h
#import <UIKit/UIKit.h>
#import "AdWhirlView.h"
#import "AdWhirlDelegateProtocol.h"
@class Reachability;
@interface NewsViewController : UIViewController<AdWhirlDelegate, UIScrollViewDelegate>{
AdWhirlView *adView;
IBOutlet UILabel *labelBody;
IBOutlet UILabel *titleView;
IBOutlet UILabel *subTitle;
IBOutlet UILabel *date;
IBOutlet UIScrollView *scrollView;
IBOutlet UIScrollView *imageScrollView;
IBOutlet UIImageView *backgroundImage;
IBOutlet UIImage *mainImage;
IBOutlet UIPageControl *pageControl;
NSInteger numberOfPages;
NSMutableArray *imageURL;
}
@property(nonatomic,retain)AdWhirlView *adView;
@property (nonatomic, retain) NSMutableArray *imageURL;
@property (nonatomic, retain) IBOutlet UIPageControl *pageControl;
@property (nonatomic, retain) IBOutlet UIScrollView *imageScrollView;
@property (nonatomic, weak) IBOutlet UIImageView *backgroundImage;
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) IBOutlet UIImage *mainImage;
@property (nonatomic, strong) NSString *newsText;
@property (nonatomic, strong) NSString *newsTitle;
@property (nonatomic, strong) NSString *newsDate;
@property (nonatomic, assign) NSInteger numberOfPages;
@property (nonatomic, strong) IBOutlet UILabel *titleView;
@property (nonatomic, strong) IBOutlet UILabel *labelBody;
@property (nonatomic, strong) IBOutlet UILabel *subTitle;
@property (nonatomic, strong) IBOutlet UILabel *date;
@property (nonatomic, retain) Reachability* internetReachable;
@property (nonatomic, assign) BOOL internetActive;
-(void) checkNetworkStatus:(NSNotification *)notice;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dictionary: (NSDictionary *)dict type:(NSInteger)type numberOfPages:(NSInteger) pages image:(UIImage *)image;
- (BOOL)checkInternet;
- (void)doStuff;
- (IBAction)ad;
@end
Я использую mainImage как (UIImage *) и пытается заменить изображение в моем классе customImageView основным изображением, но ничего не отображается вверх. Что мне здесь не хватает?
Я не думаю, что вам нужно для размещения/инициализации изображения здесь: 'mainImage = [[UIImage alloc] init]; mainImage = image; ' – Marty
Я пробовал не выделять/инициализировать его, я попробовал просто установить его равным напрямую, я даже попробовал initWithCGImage и получил CGImage из образа. Ни один из них не работал – kamran619
Да, я не думал, что это поможет, просто заметила это при просмотре кода. – Marty