Iphone g:(id)viewObj; +(NSString*)dumpViewToString:(id)viewObj级别:(int)级别; @结束

Iphone g:(id)viewObj; +(NSString*)dumpViewToString:(id)viewObj级别:(int)级别; @结束,iphone,objective-c,cocoa-touch,uiimagepickercontroller,Iphone,Objective C,Cocoa Touch,Uiimagepickercontroller,我不知道具体细节(您没有提供任何代码),但我猜具有自定义背景的ViewController通过UIImageView或.backgroundColor=[UIColor WithPatternImage:image]设置了背景 不管怎样,我猜它都会消失,因为您重新创建视图和图像的引用只保存在该对象本身中(现在已被销毁)。您需要保留图像并在appdelegate中保留对其的引用 如果不清楚我的意思,这里有一些代码 AppDelegate添加 @interface AppDelegate //Stu

我不知道具体细节(您没有提供任何代码),但我猜具有自定义背景的ViewController通过UIImageView或.backgroundColor=[UIColor WithPatternImage:image]设置了背景

不管怎样,我猜它都会消失,因为您重新创建视图和图像的引用只保存在该对象本身中(现在已被销毁)。您需要保留图像并在appdelegate中保留对其的引用

如果不清楚我的意思,这里有一些代码

AppDelegate添加

@interface AppDelegate
//Stuff that's already here.
@property (nonatomic, retain) UIImage *backgroundImage;
@end
视图控制器添加

@implementation ViewController

-(void)viewDidLoad{
    self.view.backgroundImage = ((AppDelegate*)[UIApplication sharedApplication].delegate).backgroundImage;
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
    ((AppDelegate*)[UIApplication sharedApplication].delegate).backgroundImage = [image retain];  
    //background code here
}

@end

我不知道具体细节(您没有提供任何代码),但我猜具有自定义背景的ViewController的背景是通过UIImageView或.backgroundColor=[UIColor colorWithPatternImage:image]设置的

不管怎样,我猜它都会消失,因为您重新创建视图和图像的引用只保存在该对象本身中(现在已被销毁)。您需要保留图像并在appdelegate中保留对其的引用

如果不清楚我的意思,这里有一些代码

AppDelegate添加

@interface AppDelegate
//Stuff that's already here.
@property (nonatomic, retain) UIImage *backgroundImage;
@end
视图控制器添加

@implementation ViewController

-(void)viewDidLoad{
    self.view.backgroundImage = ((AppDelegate*)[UIApplication sharedApplication].delegate).backgroundImage;
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
    ((AppDelegate*)[UIApplication sharedApplication].delegate).backgroundImage = [image retain];  
    //background code here
}

@end

真漂亮+一个伟大的片段。@BP,好吧,你可以告诉你所有的朋友…:-)真漂亮+一个伟大的片段。@BP,好吧,你可以告诉你所有的朋友…:-)感谢您的理解和一段很好的代码片段,但是除了我提供的信息之外,我还想提到我正在更改UIButton
[myBtn setBackgroundImage:img forState:UIStateNormal
。请在此场景中为我提供更多指导。谢谢。忽略我之前的评论。您建议的代码非常有用:)谢谢。解决此问题后,我将面临更多问题,很快会回复您:)谢谢您的理解和一段漂亮的代码片段,但除此之外n在我提供的信息中,我还想提及我正在更改UIButton
[myBtn setBackgroundImage:img forState:UIStateNormal
。请在此场景中为我提供更多指导。谢谢。忽略我之前的评论。您建议的代码非常有效:)谢谢!解决此问题后,我将面临更多问题,稍后将与您联系:)
@implementation ViewController

-(void)viewDidLoad{
    self.view.backgroundImage = ((AppDelegate*)[UIApplication sharedApplication].delegate).backgroundImage;
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
    ((AppDelegate*)[UIApplication sharedApplication].delegate).backgroundImage = [image retain];  
    //background code here
}

@end