0

i am a beginner with ios programming, my project set it autorelease, and now i get a problem with autorelease function. i show my code and hope you can suport me to avoid this

- (void)initPhotoImage
{
    photoImage = [[MyPhotoImageView alloc] initWithFrame:CGRectMake(5, 30, 0, 0)];
    photoImage.photoViewController = self;
    [photoView addSubview:photoImage];

    UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeft:)];
    gesture.direction = UISwipeGestureRecognizerDirectionLeft;
    [photoView addGestureRecognizer:gesture];
    UISwipeGestureRecognizer *gesture1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)];
    gesture1.direction = UISwipeGestureRecognizerDirectionRight;
    [photoView addGestureRecognizer:gesture1];

}

-(void)didSwipeLeft:(UIGestureRecognizer *)gestureRecognizer {

    if(self.nextViewController != NULL){
        [UIView animateWithDuration:1 animations:^{
            self.view.frame = CGRectMake(-1*self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
        }];
        NSLog(@"next");
    }else{
        NSLog(@"next view is null");
    }
}

this 2 functions in a same class, i print self.nextViewController in the init function, it print a address but in swip function, i print self.nextViewController again but it print null address, in .h file i defined it retain

@property (retain, nonatomic) MyPhotoViewController *nextViewController;
Makio
  • 465
  • 6
  • 15

1 Answers1

-2

Change this

if(self.nextViewController != NULL)

to

if(self.nextViewController != nil)
Saran
  • 6,274
  • 3
  • 39
  • 48
  • 1
    Are you sure about this? I thought Nil (capital N) is for testing if classes are nil. nil (lowercase n) is for testing objects. – rickerbh Feb 27 '13 at 04:00
  • 1
    Actually both are same. They're all zero, but "NULL" is a void *, "nil" is an id, and "Nil" is a Class pointer. – Praveen-K Feb 27 '13 at 04:05
  • what mean with this change, i think nil and null have a same mean – Makio Feb 27 '13 at 04:07
  • If both are same and replaceable, any idea why language has two? They can simply had one. – Saran Feb 27 '13 at 04:09
  • @Makio, a more detailed answer here http://stackoverflow.com/questions/557582/null-vs-nil-in-objective-c – Saran Feb 27 '13 at 04:11
  • thanks for your comment but in my case, in init function i print address that ok, but in after function i print it's address, it print 0x0000 @@, i think this problem is autorelease and i want avoid it @@ – Makio Feb 27 '13 at 04:12
  • Check if anywhere you are accidentally setting nil like self.nextViewController = nil, while you intended to do comparison with ==. That's one possibility i could guess from the shown code. – Saran Feb 27 '13 at 04:25
  • i call nextViewController only a little time in this code and i am sure your case is not exist – Makio Feb 27 '13 at 04:34