2012-07-21 47 views
0

作爲「引用統計對象使用後被使用了」的內存警告被引用統計對象被使用後被使用

對此,我也嘗試了autorelease。但沒用。

下面是給出警告的代碼。問題是什麼。請讓我知道

UICustomSwitch *switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero]; 
       [switchView initWithFrame:CGRectMake(180,5,260,30)]; 
       [switchView setOn:YES]; 
       mySearchType = 1; 
       [[switchView rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]]; 
       [[switchView leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]]; 
       [switchView addTarget:self action:@selector(switchToggled:)forControlEvents:UIControlEventValueChanged]; 
       [cell.contentView addSubview:switchView]; 
+0

你爲什麼初始化你SWITCHVIEW兩次? – 2012-07-21 12:16:18

+0

我同意盧元,你可能剛剛用框架首次啓動它,而不是cgrectzero。順便說一句,我不認爲你粘貼的代碼顯示完整的圖片 - 從代碼中,switchview似乎沒有被訪問的背景下,所以嫌疑人是單元格 - 它可能已經被釋放。你可以發佈整個方法嗎? – maranas 2012-07-21 12:22:10

回答

3

更改下面的代碼

UICustomSwitch *switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero]; 
       [switchView initWithFrame:CGRectMake(180,5,260,30)]; 

UICustomSwitch *switchView = [[UICustomSwitch alloc] initWithFrame:CGRectMake(180,5,260,30)]; 
+0

thnaks很多幫助。 – user198725878 2012-07-21 12:32:02

+0

@ user198725878我的榮幸:) – 2012-07-21 12:42:04