0

我是ios编程的初学者,我的项目将它设置为自动释放,现在我遇到了自动释放功能的问题。我展示了我的代码,希望你能支持我避免这种情况

- (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");
    }
}

这两个函数在同一个类中,我在 init 函数中打印 self.nextViewController,它打印一个地址,但在 swip 函数中,我再次打印 self.nextViewController 但它打印空地址,在 .h 文件中我定义它保留

@property (retain, nonatomic) MyPhotoViewController *nextViewController;
4

1 回答 1

-2

改变这个

if(self.nextViewController != NULL)

if(self.nextViewController != nil)
于 2013-02-27T03:56:28.517 回答