2011-10-31 43 views
-1

我创建视图并释放所有对象。我用NSTimer和NSTimer和UIView内存错误

//at viewdidload 
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 15.0 
                 target: self 
                selector:@selector(selectorSwitcher:) 
                userInfo: nil repeats:YES]; 
    NSRunLoop *runner = [NSRunLoop currentRunLoop]; 
    [runner addTimer:timer forMode: NSDefaultRunLoopMode]; 

-(void)selectorSwitcher:(NSTimer *)timer { 
     [self viewDidLoad]; 
} 

但myviews不能从滚动视图中删除。为他人创造更多的意见。我该如何解决这个问题? 感谢

if (tempView.frame.origin.x > createview.frame.size.width) { 


      tempLabel = [[UILabel alloc] initWithFrame:CGRectMake((lblname_marginleft + (i * widthOfView))-((i/sutun)*mview_width), lblname_margintop + ((i/sutun) * heightOfView), labelwidth, labelheight)]; 

      tempNumber = [[UILabel alloc] initWithFrame:CGRectMake((lblnumber_marginleft + (i* widthOfView))-((i/sutun)*mview_width), lblnumber_margintop + ((i/sutun) * heightOfView), labelwidth, labelheight)]; 

      tempyuzde= [[UILabel alloc] initWithFrame:CGRectMake((15 + (i*widthOfView))-((i/sutun)*mview_width), 10 + ((i/sutun) * heightOfView), labelwidth, labelheight)]; 

      tempView = [[UIView alloc] initWithFrame:CGRectMake((10 + (i* widthOfView)) - ((i/sutun)*mview_width), ((i/sutun) * heightOfView), widthOfView, heightOfView)]; 

回答

2

你不应该调用viewDidLoad - 系统调用一次的观点已经加载。要加载的观点,简单地做:

UIView *view = self.view; 

调用self.view式装载的XIB文件。然而,系统也会在需要时自动加载视图 - 您尝试实现哪些功能?


而且,你不应该调用

NSRunLoop *runner = [NSRunLoop currentRunLoop]; 
[runner addTimer:timer forMode: NSDefaultRunLoopMode]; 

由于通过调用scheduledTimerWithTimeInterval...你已经排定的计时器 - 你不需要再调度。