2011-10-31 68 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...你已經排定的計時器 - 你不需要再調度。