我从 Apple 提供的基于 PageView 的标准应用程序模板开始。现在我希望应用程序中的页面显示图像而不是文本。数组创建如下:
_pageData = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
nil];
此数组按以下方式处理:
DataViewController *dataViewController = [storyboard instantiateViewControllerWithIdentifier:@"DataViewController"];
dataViewController.dataObject = [self.pageData objectAtIndex:index];
return dataViewController;
然后,在 DataViewController.h 中:
@interface DataViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) UIImage *dataObject;
在 DataViewController.m 中,我尝试以下列方式在 de imageView 中显示图像:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.imageView = [[UIImageView alloc] initWithImage:_dataObject];
NSLog(@"dataObject %@", _dataObject);
}
但是,使用这段代码,我无法成功地将图像放到 PageViewController 上。知道我怎样才能让它正常工作吗?
非常感谢您的帮助!
最佳答案
这里
self.imageView = [[UIImageView alloc] initWithImage:_dataObject];
您正在创建一个新的 UIImageView,它悬卡在未使用、不可见且没有父对象的周围。 您需要以某种方式设置它的大小并使用
将其放入父 View[<parent> addSubview:self.imageView]
显示它。
如果您的原始 UIImageView 是从资源文件中读取的(我假设是这样,因为它是一个 IBOutlet ), 只是做一个
self.imageView.image = _dataObject
这应该可以代替。
关于ios - 获取 UIImageView 中的图像数组(在 UIPageViewController 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10299425/