为什么我的刷新控件会保留我的UIViewController?

时间:2013-11-17 15:40:40

标签: ios iphone objective-c dealloc

我有一个简单的刷新控件,我添加到视图控制器的视图中,导致它永远不会被释放。可能是什么原因造成的?

   pullRefresh = [[ScrollRefresh alloc] initWithFrame:CGRectMake(10, -30, self.view.frame.size.width-20, 2)];
   [pullRefresh addTarget:self selector:@selector(refreshFeed)];
   [self.feedTable addSubview:pullRefresh];

ScrollRefresh.h

@interface ScrollRefresh : UIView<DragMenuDelegate>{

    int width;
    UIView *clip;
    id target;
    SEL selector;
}


-(void)addTarget:(id)t selector:(SEL)sel;

ScrollRefresh.m

@implementation ScrollRefresh

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        self.backgroundColor = kClearColor;
        self.layer.cornerRadius = self.frame.size.height/2;
        self.layer.masksToBounds = YES;


        clip = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, self.frame.size.height)];
        clip.layer.cornerRadius = self.frame.size.height/2;
        clip.backgroundColor = UIColorFromRGB(kTweetColor, 1.0);
        [self addSubview:clip];



    }
    return self;
}

-(void)addTarget:(id)t selector:(SEL)sel{

    target = t;
    selector = sel;

}

-(void)didScroll:(float)o{

    if(o<0)o *= -1;
    width = o*2.8;
    if(width > self.frame.size.width) width = self.frame.size.width;

    if(width < self.frame.size.width){
        ChangeFrameWidth(clip, width);
    }


}


-(void)endRefreshing{

    if(width >= self.frame.size.width-5){

         #pragma clang diagnostic push
         #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        if(target)[target performSelector:selector withObject:nil];
         #pragma clang diagnostic pop
    }

}

1 个答案:

答案 0 :(得分:1)

ScrollRefresh中的目标定义为强。添加__weak修饰符。

相关问题