2

Bellow 是我的 didFinishPickingMediaWithInfo 方法,我知道我有很多不必要的代码、保留、发布等......但这是我可以让它工作的方式,我害怕在尝试优化它时破坏它。

任何人都可以帮我脱掉不必要的东西并让这个方法干净吗?

另外,我有一个视图控制器,它将加载 4 张照片(相机胶卷或相机),在选择器选择第二张或第三张照片后,应用程序崩溃,或者至少,我收到了下面的这些警报之一。我做错了什么?谢谢!

-2012-06-23 10:54:07.399 LookdoDia[6525:707] 收到内存警告。

-wait_fences:未能收到回复:10004003

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [self dismissModalViewControllerAnimated:YES];   

    UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
    if(!img) img = [info objectForKey:UIImagePickerControllerOriginalImage];

    uiimvImagem.image = [img retain];
    uiimvImagem.alpha = 0;
    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:img];
    self.uiimvImagem = [tempImageView retain];
    [tempImageView release];

    CGRect frame = uiimvImagem.frame;
    frame.size.width = 359;
    frame.size.height = img.size.height / (img.size.width / 359);
    uiimvImagem.frame = frame;

    uisv1.showsVerticalScrollIndicator = NO;
    uisv1.showsHorizontalScrollIndicator = NO;
    uisv1.contentSize = CGSizeMake(uiimvImagem.frame.size.width, uiimvImagem.frame.size.height);
    uisv1.maximumZoomScale = 3.0;
    uisv1.minimumZoomScale = 0.8;
    uisv1.clipsToBounds = YES;
    uisv1.delegate = self;

    [uisv1 addSubview:uiimvImagem];

    [img release];

}
4

1 回答 1

6
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
    if(!img) img = [info objectForKey:UIImagePickerControllerOriginalImage];

    uiimvImagem.image = img; //why bother?
    uiimvImagem.alpha = 0; //why bother?
    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:img];
    self.uiimvImagem = tempImageView; //Make sure your self.uiimvImagem is a retained property! Also, don't forget to nil it out in your dealloc method
    [tempImageView release];

    CGRect frame = uiimvImagem.frame;
    frame.size.width = 359;
    frame.size.height = img.size.height / (img.size.width / 359);
    uiimvImagem.frame = frame;

    uisv1.showsVerticalScrollIndicator = NO;
    uisv1.showsHorizontalScrollIndicator = NO;
    uisv1.contentSize = CGSizeMake(uiimvImagem.frame.size.width, uiimvImagem.frame.size.height);
    uisv1.maximumZoomScale = 3.0;
    uisv1.minimumZoomScale = 0.8;
    uisv1.clipsToBounds = YES;
    uisv1.delegate = self;

    [uisv1 addSubview:uiimvImagem];

    [self dismissModalViewControllerAnimated:YES];   

}

这应该会好一点——虽然我不确定其余部分是如何连接的(即属性声明,我不确定 uisv1 分配在哪里。)仍然有一些看起来不正确的东西——你正在分配一个图像到图像视图,然后使用新分配的 UIImageView 运行整个过程。

于 2012-06-23T14:22:17.970 回答