iOS / ObjectiveC:我尝试用包含本地图像的图像视图打开一个视图控制器,但它显示一个白页

问题描述 投票:0回答:1

我准确地说,当我使用调试器时,我可以在图像视图中看到图像。 为什么它显示一个白页? (我可以看到后退按钮)

- (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];
    }
ios objective-c uiviewcontroller uiimageview uiimage
1个回答
0
投票
UIImageView *imageView= [UIImageView new];
imageView.image = [UIImage imageWithContentsOfFile: filePath];
[imageViewController.view addSubview:imageView];

与您的按钮不同,您的

imageView
没有框架,也没有尺寸。因此它是左上角的一个无穷小点,你看不到它。

除此之外,您的代码很糟糕。永远不要从另一个视图控制器填充视图控制器的视图。制作一个图像视图控制器class并让它填充自身.

© www.soinside.com 2019 - 2024. All rights reserved.