Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 关闭SecondViewController时,firstViewController中的UIButton未正确更改图像_Ios_Uiviewcontroller_Uibutton_Viewdidload - Fatal编程技术网

Ios 关闭SecondViewController时,firstViewController中的UIButton未正确更改图像

Ios 关闭SecondViewController时,firstViewController中的UIButton未正确更改图像,ios,uiviewcontroller,uibutton,viewdidload,Ios,Uiviewcontroller,Uibutton,Viewdidload,我正在从SecondView控制器保存图像并调整其大小。 然后,当我回到Firstview控制器时,该控制器上的按钮图像必须 可以从刚保存的图像文件中加载 图像部分显示(仅显示图像的顶部)。但如果我再次转到SecondViewController,不再保存图像并返回到第一个ViewController,按钮图像将完全显示并看起来很好 - (void)showImageFirst { //Show thumb image in button. NSArray *sysPath

我正在从SecondView控制器保存图像并调整其大小。
然后,当我回到Firstview控制器时,该控制器上的按钮图像必须 可以从刚保存的图像文件中加载

图像部分显示(仅显示图像的顶部)。但如果我再次转到SecondViewController,不再保存图像并返回到第一个ViewController,按钮图像将完全显示并看起来很好

- (void)showImageFirst { 

    //Show thumb image in button.

    NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
    NSString *docDirectory = [sysPaths objectAtIndex:0];
    NSString *filePath = [NSString stringWithFormat:@"%@/thumbtest.png", docDirectory];
    UIImage *tempimage = [[UIImage alloc] initWithContentsOfFile:filePath];

    [imageForButton setImage:tempimage forState:UIControlStateNormal];
}
我在ViewDiDLoad中调用它,我还尝试将它放在ViewDidDisplay中:

-(void)viewWillAppear {
    [self.showImageFirst];
    [super viewWillAppear:animated];
}

可以使第一个视图控制器成为第二个视图控制器的委托

然后将UIImage从第二个视图控制器传递回第一个视图控制器,而不是将映像保存到磁盘,然后从磁盘重新加载


我还没有检查,但我几乎可以肯定,将映像保存到磁盘是异步运行的,因此,当您再次尝试加载映像时,可能没有保存映像。

非常感谢!好主意!我在1中执行了2个操作(视图分段时保存并委派),id不起作用!)现在一切都好了!)很好:)喜欢它,当你让一些东西优雅地工作,你可以用更少的代码做更多的事情。