en iOS5 mis métodos para cambiar imágenes en la galería son malos

I have some classes for watching pictures in gallery. in those classes after enabling ARC i get message that implicit conversion is forbidden by ARC and I cant run the application.

Those methods are:

- (void) curlToPrevious
{
    if (currentImageIndex == 0) return;



         if ([self.image2 superview] == NO) {

        self.image2.image = (UIImage*) [imageViews objectAtIndex:(currentImageIndex-1)];
    } else {
        self.image1.image = (UIImage*) [imageViews objectAtIndex:(currentImageIndex-1)];
    }

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration];

    currentImageIndex--;

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.containerView cache:YES];

    if ([self.image2 superview] == NO) {
        [self.image1 removeFromSuperview];
        [self.containerView addSubview:self.image2];
    } else {
        [self.image2 removeFromSuperview];
        [self.containerView addSubview:self.image1];
    }

    [UIView commitAnimations];
    [self updateCurrentImageCounter];
}

- (void) curlToNext
{
    if (currentImageIndex == ([self imageCount]-1)) return;

    if ([self.image2 superview] == NO) {
        self.image2.image = (UIImage*) [imageViews objectAtIndex:(currentImageIndex+1)];
    } else {
        self.image1.image = (UIImage*) [imageViews objectAtIndex:(currentImageIndex+1)];
    }
    currentImageIndex++;


    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:kTransitionDuration];

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.containerView cache:YES];

    if ([self.image2 superview] == NO) {
        [self.image1 removeFromSuperview];
        [self.containerView addSubview:self.image2];
    } else {
        [self.image2 removeFromSuperview];
        [self.containerView addSubview:self.image1];
    }

    [UIView commitAnimations];
    [self updateCurrentImageCounter];
}

He

if ([self.image2 superview] == NO) {

In this line on 4 places in code problem.

The text I get is:

implicit conversion of 'int' to 'UIView' is disallowed with ARC

How can I avoid this??? Thanks.

preguntado el 08 de noviembre de 11 a las 14:11

2 Respuestas

you can replace your code on this if ([self.image2 superview] == nil)

respondido 08 nov., 11:18

You are comparing an UIView* con una entero (0) - of course you get a warning. Do you want to check whether the superview is nil? Then just do that:

if([self.image2 superview] == nil) { ... }

respondido 08 nov., 11:18

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.