提问人:ΩlostA 提问时间:3/8/2023 更新时间:3/8/2023 访问量:26
iOS / ObjectiveC:我尝试打开一个带有包含本地图像的 imageview 的视图控制器,但它显示一个白页
iOS / ObjectiveC: I try to open a viewcontroller with an imageview containing a local image, but it displays a white page
问:
我精确地指出,当我使用调试器时,我可以在图像视图中看到图像。 为什么它显示白页?(我可以看到后退按钮)
- (void) openIMAGE:(NSIndexPath *) indexPath
{
NSString *filePath = [menuPath stringByAppendingPathComponent:contentsList[indexPath.row]];
UIViewController* imageViewController = [UIViewController new];
imageViewController.view.backgroundColor = [UIColor whiteColor];
//0,21,73,30
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(backBtn:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Back" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 21.0, 73.0, 30.0);
UIImageView *imageView= [UIImageView new];
imageView.image = [UIImage imageWithContentsOfFile: filePath];
// UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + 48.0, self.view.frame.size.width, self.view.frame.size.height - 48.0)];
[imageViewController.view addSubview:imageView];
[imageViewController.view addSubview:button];
[self.navigationController pushViewController:imageViewController animated:YES];
}
答:
1赞
matt
3/8/2023
#1
UIImageView *imageView= [UIImageView new];
imageView.image = [UIImage imageWithContentsOfFile: filePath];
[imageViewController.view addSubview:imageView];
与您的按钮不同,您的按钮没有框架,也没有大小。因此,它是左上角的无穷小点,你看不到它。imageView
除此之外,你的代码是残酷的。切勿从另一个视图控制器填充视图控制器的视图。创建一个图像视图控制器类,并让它填充自身。
评论