我是ios编程的初学者,我的项目设置为autorelease,现在我遇到了自动释放功能的问题。我展示了我的代码,并希望你可以支持我避免这个
- (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;
答案 0 :(得分:-2)
更改此
if(self.nextViewController != NULL)
到
if(self.nextViewController != nil)