首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在autorelease ios项目中保留变量

在autorelease ios项目中保留变量
EN

Stack Overflow用户
提问于 2013-02-27 11:52:19
回答 1查看 122关注 0票数 0

我是ios编程的初学者,我的项目设置了自动发布,现在我在自动发布功能上遇到了问题。我展示了我的代码,希望您能支持我以避免这种情况

代码语言:javascript
复制
- (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文件中我定义它保留

代码语言:javascript
复制
@property (retain, nonatomic) MyPhotoViewController *nextViewController;
EN

回答 1

Stack Overflow用户

发布于 2013-02-27 11:56:29

改变这一点

代码语言:javascript
复制
if(self.nextViewController != NULL)

代码语言:javascript
复制
if(self.nextViewController != nil)
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15103884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档